Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix pkgutil.iter_modules call #207

Merged

Conversation

KevinHock
Copy link
Contributor

@KevinHock KevinHock commented Dec 5, 2021

Give a list of str rather than a list of PosixPath

On Python 3.9.5:

>>> import email
>>> email.__path__
['/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/email']
>>> email.__path__[0]
'/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/email'
>>> type(email.__path__[0])
<class 'str'>

The pkgutil.iter_modules docs are pretty bad on this:
path should be either None or a list of paths to look for modules in.
it doesn't specify string.

You can see a lot of other OSS projects have had bugs like this:

Stack trace for posterity was:

  File "/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/site-packages/parliament/__init__.py", line 69, in analyze_policy_string
    policy.analyze(
  File "/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/site-packages/parliament/policy.py", line 339, in analyze
    for importer, name, _ in pkgutil.iter_modules(
  File "/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/pkgutil.py", line 130, in iter_modules
    for i in importers:
  File "/Users/kevinhock/.pyenv/versions/3.9.5/lib/python3.9/pkgutil.py", line 420, in get_importer
    importer = path_hook(path_item)
  File "<frozen importlib._bootstrap_external>", line 1601, in path_hook_for_FileFinder
  File "<frozen importlib._bootstrap_external>", line 1476, in __init__
  File "<frozen importlib._bootstrap_external>", line 177, in _path_isabs
AttributeError: 'PosixPath' object has no attribute 'startswith'

Give a list of str rather than a list of PosixPath
@KevinHock
Copy link
Contributor Author

made a python issue related to this https://bugs.python.org/issue45991 but it's pretty P🤷🏼 IMO

@0xdabbad00 0xdabbad00 merged commit 201cfcb into duo-labs:main Dec 5, 2021
@0xdabbad00
Copy link
Collaborator

Thank you @KevinHock

@KevinHock
Copy link
Contributor Author

Thank you!

@KevinHock KevinHock deleted the KevinHock-fix-iter_modules-call branch December 5, 2021 19:08
@KevinHock
Copy link
Contributor Author

Hi @0xdabbad00, do you mind bumping the PyPI package with this change, whenever you get a chance? 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants