Re: Eliminating implicit __main__ relative imports
Paul Moore <[email protected]> Tue, 28 Mar 2017 11:38:27 +0100
| Newsgroups | gmane.comp.python.import |
|---|---|
| Message-ID | <CACac1F_u9ruCz0WyyFMpW7J8AJtGxiE7iMK6fLmkR=zcBC+LnQ@mail.gmail.com> |
On 28 March 2017 at 11:25, Nick Coghlan <[email protected]> wrote: > Thanks to PEP 366, cross-version compatible main-relative imports > would then look like: > > if __package__ is not None: > from . import relative_module_name > else: > import relative_module_name I'd be a little concerned that certain types of program (adhoc scripts and the like that got too big to be a single file) would be broken by this. Even if they *don't* care about cross-version compatibility, they'd need to change from "import foo" to "from . import foo". I honestly don't know how common this problem would be - I've tried to think what programs I have that would be affected, and honestly, my feeling is that it's either very few, or it's a lot but I use main-relative imports so automatically that I can't remember any ;-) (Although TBH, I think the former, based on the fact that most of my adhoc scripts are very small). The particular concern is that if it *is* an issue, it'd mostly hit the sort of code that doesn't get published on the web, so it's probably pretty hard to get a sense of the scale of the impact. In isolation, though, the idea sounds good. Paul