New submission from Rikard Nordgren <rikard.nordg...@gmail.com>:

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'

----------
components: Library (Lib)
messages: 393120
nosy: rikard.nordgren
priority: normal
severity: normal
status: open
title: Regression in pkgutil: iter_modules stopped taking Path argument in 
python 3.8.10 and 3.9.5
type: crash
versions: Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44061>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to