Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Add test case for lazy import dotted.name as name
  • Loading branch information
DinoV committed Aug 14, 2026
commit e33c76c23cfe48c2b789285a501fe8b68d0e3c37
8 changes: 8 additions & 0 deletions Lib/test/test_lazy_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ def test_non_package_lazily_imported(self):
""")
assert_python_ok("-c", code)

def test_non_package_lazily_imported_as(self):
"""Doing a dotted lazy import as still works"""
code = textwrap.dedent("""
lazy import math.pi as pi
pi
""")
assert_python_ok("-c", code)

def test_missing_attribute_raises_import_error(self):

@pablogsal pablogsal Aug 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe I am misreading this but i think this covers a different path. lazy import math.pi as pi still resolves pi to the float instead of raising.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was in response to @Yhg1s who asked about this case and commented that we don't seem to have tests for it in #155188. I can add a test case for the lazy import math.pi as pi case too.

"""Accessing a nonexistent lazy name via from import raises ImportError."""
code = textwrap.dedent("""
Expand Down
Loading