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

Handle module.__file__ == None #1042

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mitogen/master.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is more misleading than helpful. Better to remove it.

Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ def is_stdlib_name(modname):
return False

# six installs crap with no __file__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now more mislaeading than helpful, please remove it.

modpath = os.path.abspath(getattr(module, '__file__', ''))
path = getattr(module, '__file__', '')
if path is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to have an accompanying unit test for this case. If you'd like to add one I recommend doing so in tests.module_finder_test.IsStdlibNameTest, and adding the package that caused this in the wild as a test dependency in tests/requirements.txt.

Otherwise I'm happy to add one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the package might be tricky, since it seems to be a part of Python distribution, though I'm not 100% sure.
The package was backports.

Will try to reproduce on different environments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backports.* (e.g. https://pypi.org/project/backports.textwrap/) are all thrid party distributions on PyPI. They aren't part of the stdlib.

backports is a namespace package they all declare. The project on PyPI called backports (https://pypi.org/project/backports/) is a placeholder only. I don't think it is meant to be installed, and it doesn't contain an Python code.

So I recommend you use a small backports.<your choice>, or if you don't have a preference use backports.textwrap.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, thanks for clarification 👍

path = ''

modpath = os.path.abspath(path)
return is_stdlib_path(modpath)


Expand Down
Loading