Ivan Pozdeev <ivan_pozd...@mail.ru> added the comment:

On 01.03.2019 3:58, Steve Dower wrote
> Import hooks can always be injected by a package __init__.py before the 
> importer will try and resolve the module, so nothing is needed there.

I thought the flaw in this reasoning in 
https://bugs.python.org/issue33944#msg320277 was obvious and didn't want 
to bother people refuting it. Apparently not.

To do anything in __init__.py, that __init__.py itself needs to be 
already importable. This very well may not be the case -- in fact, 
import hooks were designed specifically for the scenarios where this is 
not the case.

Imagine e.g. loading modules from a cloud storage (why not?) -- so 
nothing on the system at all except the hook. Or, suggested earlier in 
this ticket, a union namespace where the code to import needs to be 
constructed on the fly.

> .pth files really only satisfy the "run at startup because I'm a dependency 
> of something that my user wants and don't make them opt-in to my changed 
> behaviour"

Startup code (custom or not) is not a dependency of anything. It rather 
customizes the environment in which the program specified by the user would 
run, _before_ any user code could be allowed to get control. It is not a part 
of the program to be run but rather of the environment that the user wants, and 
it needs to be implicit so the user can use the same commands and code (compare 
venv). This is a required feature because the stock Python startup logic cannot 
possibly provide all the customizations that a user may need (compare initrd).

.pth's are equivalent to sitecustomize but allow the user to manage the set of 
code chunks automatically using the packaging infrastructure (compare .d 
directories in UNIX). The fact that this feature is mixed up with and often 
supplements "real packages" that a program would explicitly use is actually 
incidental: a package with a .pth does not need to have any functionality 
intended for explicit use.

> which I don't like 

If you don't like something, there's always a specific reason -- though you may 
not understand it consciously. So the way to go is dig into it, find out what 
specific speck is putting you off -- only then can you be sure that you are 
concentrating on the right thing and won't throw the baby out with the 
bathwater. Try to change one trait in your mind's eye leaving all else intact 
-- will the feeling go away? If it will, you are on the right track; can the 
trait you chose be split further? You know you found it when you can't change 
any further part and change the feeling and you can say with confidence how 
exactly what it's doing misaligns with your moral compass.

We already identified a few real reasons: hard to see, hard to debug, 
encourages unreadable code, run in arbitrary order when the order matters (and 
IIRC I provided fixes for all). What else?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33944>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to