[New-bugs-announce] [issue32188] ImpImporter.find_modules removes symlinks in paths

Henk-Jaap Wagenaar report at bugs.python.org
Thu Nov 30 19:10:50 EST 2017


New submission from Henk-Jaap Wagenaar <wagenaarhenkjaap at gmail.com>:

ImpImporter.find_modules calls os.path.real on the path used:

https://github.com/python/cpython/blob/be6b74c0795b709c7a04e2187a7e32d08f5155f6/Lib/pkgutil.py#L181

This means if there is a submodule (foo.bar) which first appears on the path involving a symlink that

pkgutil.find_loader('foo').get_filename()

has the path with the symlinks removed whereas

import foo
foo.__file__

does have the symlinks. Note that is in the absence of any PEP302 import hooks.

This behaviour comes up in pytest test/plugin collection in virtual environments in Py2.7 on linux where they have a symlinked venv/local/lib before venv/lib on the path and creates problems.

There might very well be a good reason the path is made absolute here, however the test suite passes when it is reverted to path = [self.path].

----------
components: Library (Lib)
messages: 307353
nosy: Henk-Jaap Wagenaar
priority: normal
severity: normal
status: open
title: ImpImporter.find_modules removes symlinks in paths
type: behavior
versions: Python 2.7, Python 3.6, Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32188>
_______________________________________


More information about the New-bugs-announce mailing list