Message336939
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? |
|
Date |
User |
Action |
Args |
2019-03-01 17:27:23 | __Vano | set | recipients:
+ __Vano, mhammond, barry, brett.cannon, terry.reedy, jaraco, ncoghlan, pitrou, eric.smith, christian.heimes, ionelmc, SilentGhost, eric.snow, takluyver, steve.dower, veky, Ivan.Pozdeev, Anthony Sottile, ethan smith, cheryl.sabella, Chris Billington, Peter L3 |
2019-03-01 17:27:23 | __Vano | link | issue33944 messages |
2019-03-01 17:27:23 | __Vano | create | |
|