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

Fixes #281 #283

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions lib/python/pyflyby/_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def filename(self):
# Get the filename using loader.get_filename(). Note that this does
# more than just loader.filename: for example, it adds /__init__.py
# for packages.
if not hasattr(loader, 'get_filename'):
return None
filename = loader.get_filename()
if not filename:
return None
Expand Down
12 changes: 12 additions & 0 deletions tests/test_imports2s.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,18 @@ def test_replace_star_no_imports_found(capsys):
captured = capsys.readouterr()
assert 'Traceback' not in captured.err


def test_replace_star_imports_os_issue_281(capsys):
input = PythonBlock(dedent('''
from os import *

getcwd()
''').lstrip(), filename="/foo/test_replace_os_imports.py")
_ = replace_star_imports(input)
captured = capsys.readouterr()
assert 'with' in captured.out and 'imports' in captured.out


def test_replace_star_imports_1():
input = PythonBlock(dedent('''
from mod1 import f1
Expand Down
Loading