Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My question is: if you already have to put the "import" there, why not have a PEP to specify the version in that same import statement, and let `uv` scan that dependency? It's something I never understood.


This is addressed in detail the relevant ecosystem-wide standard: https://peps.python.org/pep-0723/#why-not-infer-the-requirem...

My own take:

PEP 723 had a deliberate goal of not making extra work for core devs, and not requiring tools to parse Python code. Note that if you put inline comments on the import lines, that wouldn't affect core devs, but would still complicate matters for tools. Python's import statement is just another statement that occurs at runtime and can appear anywhere in the code.

Besides that, trying to associate version numbers with the imported module is a complete non-starter. Version numbers belong to the distributions[1], which may define zero or more top-level packages. The distribution name may be completely independent from the names of what is imported, and need not even be a valid identifier (there is a standard normalization process, but that still allows your distribution's name to start with a digit, for example).

[1]: You say "packages", but I'm trying to avoid the unfortunate overloading the term. PyPA recommends (https://packaging.python.org/en/latest/discussions/distribut...) "distribution package" for what you download from PyPI, and "import package" for what you import in the code; I think this is a bit unwieldy.


They don't want tools like uv to have to parse Python, which is complex and constantly changes.

See also https://peps.python.org/pep-0723/#why-not-infer-the-requirem...


Ahh thanks for that! Makes sense, since you could also have an import somewhere down the script (although that would be bad design).

Another point is the ambiguous naming when having several packages doing roughly the same... Which is crucial here. Thank you! :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: