Skip to content

Why naming your third-party library after a standard library is a Bad Idea #118

@bengsparks

Description

@bengsparks

The top part of my venv's pathlib module contains an import of from collections import Sequence.
However this line fails, as in Python 3.10.5, there is no Sequence in collections.

The source for this seems to be a third-party backwards compatible version of pathlib that is a transitive dependency of our project.

Opening this file reveals that the line that contained the failed import in the venv has been replaced by
from _collections_abc import Sequence, which explains why this succeeds.

Executing import pathlib from the REPL succeeds, and reveals, that the import defaults to my global copy of pathlib.

(pytypes-xvtnrWJT-py3.10) benji in pytype/repo on refactor/filters ● ● λ which python
/home/benji/.cache/pypoetry/virtualenvs/pytypes-xvtnrWJT-py3.10/bin/python                                                                                                                                                                                                                                                                                                    /0.0s
(pytypes-xvtnrWJT-py3.10) benji in pytype/repo on refactor/filters ● ● λ python
Python 3.10.5 (main, Jun  6 2022, 18:49:26) [GCC 12.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
>>> pathlib.__file__
'/usr/lib/python3.10/pathlib.py'

This can be fixed by simply removing the file from the virtualenv, which makes the "real" pathlib take precedence.
A nicer fix would be to track down which library installs this and to rip it out.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions