Author rikard.nordgren
Recipients rikard.nordgren
Date 2021-05-06.17:54:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620323641.82.0.334230031538.issue44061@roundup.psfhosted.org>
In-reply-to
Content
The pkgutil.iter_modules crash when using Path object in the first argument. The code below works in python 3.8.9 and 3.9.4, but stopped working in python 3.8.10 and 3.9.5. Changing from Path to str works in all versions.


import pkgutil
from pathlib import Path

for _, modname, ispkg in pkgutil.iter_modules([Path("/home")], 'somepackage.somesubpackage'):
        print(modname, ispkg)


Error message from python 3.8.10 (other path was used):

Traceback (most recent call last):
  File "/home/devel/Python-3.8.10/Lib/pkgutil.py", line 415, in get_importer
    importer = sys.path_importer_cache[path_item]
KeyError: PosixPath('/home/devel/pharmpy/src/pharmpy/plugins')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pyissue.py", line 5, in <module>
    for _, modname, ispkg in pkgutil.iter_modules([Path("/home/devel/pharmpy/src/pharmpy/plugins")], 'pharmpy.plugins'):
  File "/home/devel/Python-3.8.10/Lib/pkgutil.py", line 129, in iter_modules
    for i in importers:
  File "/home/devel/Python-3.8.10/Lib/pkgutil.py", line 419, in get_importer
    importer = path_hook(path_item)
  File "<frozen importlib._bootstrap_external>", line 1594, in path_hook_for_FileFinder
  File "<frozen importlib._bootstrap_external>", line 1469, in __init__
  File "<frozen importlib._bootstrap_external>", line 177, in _path_isabs
AttributeError: 'PosixPath' object has no attribute 'startswith'
History
Date User Action Args
2021-05-06 17:54:01rikard.nordgrensetrecipients: + rikard.nordgren
2021-05-06 17:54:01rikard.nordgrensetmessageid: <1620323641.82.0.334230031538.issue44061@roundup.psfhosted.org>
2021-05-06 17:54:01rikard.nordgrenlinkissue44061 messages
2021-05-06 17:54:01rikard.nordgrencreate