News for hackers. Stuff that matters.
Re:Uv's killer feature is pulling in local dependencies by zahlman on Monday January 13, 2025 @02:32AM (#42681004)
Yep, happens all the time with the standard library. Nowadays, third-party libraries have this issue much less because they can use relative imports except for their dependencies. But the Python standard library, for historical reasons, isn't organized into a package, so it can't do that.

Here's a fun one (this was improved in 3.11, but some other names like `traceback.py` can still reproduce a similar problem):

  /tmp$ touch token.py
  /tmp$ py3.10
  Python 3.10.14 (main, Jun 24 2024, 03:37:47) [GCC 11.4.0] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>> help()
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/opt/python/standard/lib/python3.10/_sitebuiltins.py", line 102, in __call__
      import pydoc
    File "/opt/python/standard/lib/python3.10/pydoc.py", line 62, in <module>
      import inspect
    File "/opt/python/standard/lib/python3.10/inspect.py", line 43, in <module>
      import linecache
    File "/opt/python/standard/lib/python3.10/linecache.py", line 11, in <module>
      import tokenize
    File "/opt/python/standard/lib/python3.10/tokenize.py", line 36, in <module>
      from token import EXACT_TOKEN_TYPES
  ImportError: cannot import name 'EXACT_TOKEN_TYPES' from 'token' (/tmp/token.py)
Related Stack Overflow Q&A (featuring an answer from me): https://stackoverflow.com/questions/36250353

There are no comments on this comment yet.