[python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
It says they are "highly discouraged" because "absolute imports are more portable and usually more readable", but now that people have had a chance to use explicit relative imports, do people still believe this? I mean if we truly believed this then why did we add the syntax? I know I have used it and love it, let alone that I don't buy the portability argument. ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
On Fri, Feb 18, 2011 at 3:36 PM, Brett Cannon wrote: > It says they are "highly discouraged" because "absolute imports are > more portable and usually more readable", but now that people have had > a chance to use explicit relative imports, do people still believe > this? I mean if we truly believed this then why did we add the syntax? > I know I have used it and love it, let alone that I don't buy the > portability argument. I suspect the portability argument is about cross-Python-version compatibility, rather than across operating systems. Maybe we don't care about that any more since 2.4 and earlier don't exist in the eyes of python-dev. On the other hand, I've never used them, or stumbled over code that does, so I won't speak to the readability issue. I have an opinion, but no practical experience with explicit relative imports. -Fred -- Fred L. Drake, Jr. "A storm broke loose in my mind." --Albert Einstein ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
Le vendredi 18 février 2011 à 12:36 -0800, Brett Cannon a écrit : > It says they are "highly discouraged" because "absolute imports are > more portable and usually more readable", but now that people have had > a chance to use explicit relative imports, do people still believe > this? I mean if we truly believed this then why did we add the syntax? > I know I have used it and love it, let alone that I don't buy the > portability argument. I personally find it confusing and unreadable, and I much prefer when I don't have to decipher it (especially non-trivial variants such as "from ..foo import bar"). Just my 2 cents Antoine. ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
On Fri, Feb 18, 2011 at 3:59 PM, Antoine Pitrou wrote: > (especially non-trivial variants such as "from ..foo import bar"). Eeewe. More than one leading "." should be considered a bug. -Fred -- Fred L. Drake, Jr. "A storm broke loose in my mind." --Albert Einstein ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
Brett Cannon wrote: > It says they are "highly discouraged" because "absolute imports are > more portable and usually more readable", but now that people have had > a chance to use explicit relative imports, do people still believe > this? I mean if we truly believed this then why did we add the syntax? > I know I have used it and love it, let alone that I don't buy the > portability argument. Let's put it this way: I think that PEP 8 gets way too much attention in Python land. It describes one way of doing things, but is not a bible or strict style guide (and even says that). Regarding relative imports: I think they were only added to be able to port code that uses Python2-style imports (which are relative as first try, then absolute) gradually to code that uses absolute imports. In all our larger projects we use absolute imports and this has often helped in organizing the code, finding definitions, etc. So far, we've not had any use for relative imports, but I can imagine some uses for e.g. plugin modules and component architectures that can be dropped into existing Python packages. Relative imports can also help porting code when doing package structure changes, e.g. moving top-level modules into a package. -- Marc-Andre Lemburg ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
On Fri, Feb 18, 2011 at 3:36 PM, Brett Cannon wrote: > It says they are "highly discouraged" because "absolute imports are > more portable and usually more readable", but now that people have had > a chance to use explicit relative imports, do people still believe > this? I mean if we truly believed this then why did we add the syntax? > I know I have used it and love it, let alone that I don't buy the > portability argument. I've been living so long with versions of Python that didn't have explicit relative imports, I'd forgotten why I wanted them in in the first place. My initial reaction was that absolute imports are good enough, but that there are special cases where relative imports are needed and explicit relative imports address that need, so I'm sure we need the feature. Thinking about it more though, I *like* explicit relative imports because I think they can reduce the burden of reading the code. When you see: from . import foo You know that foo is local to (part of) this project. Of course, if you see: import thisproject.foo You know that foo is part of ``thisproject``, but you also have to remember that ``thisproject`` is *this* project. :) How useful this is can certainly be debated. I think I'd have to use the explicit relative import style in practice for a while before I was sure I liked it. I think I'll make a point of trying it out. Of course, the explicit relative import style makes moving packages around *somewhat* easier. I agree with Marc-Andre. We shouldn't worry too much about what PEP 8 says. Jim -- Jim Fulton http://www.linkedin.com/in/jimfulton ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
On Fri, Feb 18, 2011 at 10:35 PM, M.-A. Lemburg wrote: > Brett Cannon wrote: >> It says they are "highly discouraged" because "absolute imports are >> more portable and usually more readable", but now that people have had >> a chance to use explicit relative imports, do people still believe >> this? I mean if we truly believed this then why did we add the syntax? >> I know I have used it and love it, let alone that I don't buy the >> portability argument. > > Let's put it this way: I think that PEP 8 gets way too much > attention in Python land. > > It describes one way of doing things, but is not a bible or > strict style guide (and even says that) Yeah but it exists. And it very useful to have, I'd say. 1 - when you start Python, it gives you a sense of how a "beautiful" Python code should look. 2 - for any new project, I personally recommend strict PEP 8 instead of inventing another convention. 3 - It's documented, widely adopted, and we have existing tools to check for compliancy out there. Cheers Tarek -- Tarek Ziadé | http://ziade.org ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
Re: [python-committers] do we still believe explicit relative imports are bad as PEP 8 claims?
On Feb 18, 2011, at 12:36 PM, Brett Cannon wrote: > It says they are "highly discouraged" because "absolute imports are > more portable and usually more readable", but now that people have had > a chance to use explicit relative imports, do people still believe > this? I mean if we truly believed this then why did we add the syntax? > I know I have used it and love it, let alone that I don't buy the > portability argument. I still find relative imports to be a bit jarring and don't like the implied tight coupling of modules. The nest of relative imports in unittest is a good example of something that causes a mental hiccup when I read it and it seems like an anti-pattern. Raymond Lib/unittest/__init__.py from .result import TestResult from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf, skipUnless, expectedFailure) from .suite import BaseTestSuite, TestSuite from .loader import (TestLoader, defaultTestLoader, makeSuite, getTestCaseNames, findTestCases) from .main import TestProgram, main from .runner import TextTestRunner, TextTestResult from .signals import installHandler, registerResult, removeResult, removeHandler ___ python-committers mailing list [email protected] http://mail.python.org/mailman/listinfo/python-committers
