Closed melinath closed 10 years ago
I don't have a too specific opinion on this regard. I tend to prefer relative imports in bigger projects, but I don't consider floppyforms as one.
Are there any technical, hard facts why absolute imports are better than relative ones?
"explicit relative imports are an acceptable alternative to absolute imports, especially when dealing with complex package layouts where using absolute imports would be unnecessarily verbose"
There's a difference between implicit relative imports and explicit relative imports. PEP8 strongly says to avoid the former but floppyforms uses the latter. IMO there is no gain in doing from floppyforms import fields
compared to from . import fields
.
There's at least one reason why explicit relative are better than absolute: vendoring :) Admittedly not a common practice but with explicit relative imports you can vendor a library without having to change anything in it.
It just feels (c)leaner / more modern. Django, requests, Flask, among others, use explicit relative imports in some parts or all of their codebase. Note that pep8 was updated last summer with that note about explicit relative imports:
http://bugs.python.org/file31109/issue18472_pep_8_update5.diff
From "style of explicit relative imports is actively discouraged" to "explicit relative imports are an acceptable alternative to absolute imports" :)
Oh hey, that's new. Didn't notice the change. Thanks for the update.
I personally still prefer absolute imports because of their extra explicitness, especially since I don't value vendoring given the existence of pip. It's cool that explicit relative imports are now more accepted, but the primary use case stated in the PEP is complex project layouts - though that being said, requests and flask have extremely simple layouts and still use relative imports. * shrug *
So in that case I prefer to stick to explicit relative imports as long as PEP8 allows them. Thanks for the clarification and input.
floppyforms uses relative imports all over the place. It could be nice to switch these to absolute imports, as recommended by PEP8.