-
Notifications
You must be signed in to change notification settings - Fork 52
[CG-10888] fix: Wildcard resolution #612
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. Additional details and impacted files |
Overall Assessment: Strengths:
Minor Suggestions:
|
tests/unit/codegen/sdk/python/import_resolution/test_import_resolution.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the implementation consistent between typescript and python? https://github.com/codegen-sh/codegen-sdk/blob/09578e213d20921bf105e3d87c06d477e8af83b8/src/codegen/sdk/core/import_resolution.py#L333
Here's how typescript does it right now.
My understanding of the current situation
# file a
TEST_CONST = 1
TEST_CONST2 = 1
# file b
from filea import *
t = TEST_CONST # Works in python and typescript
# file c
from fileb import TEST_CONST # Doesn't work in python before this PR, should work in typescript afaik
# file d
from fileb import TEST_CONST2 # Would add a duplicate edge pointing to TEST_CONST in python, works in typescript afaik
Here's a test case that demonstrates the file d edge case.
def test_import_resolution_init_wildcard(tmpdir: str) -> None:
"""Tests that named import from a file with wildcard resolves properly"""
# language=python
content1 = """TEST_CONST=2
foo=9
"""
content2 = """from testdir.test1 import *
bar=foo
test=TEST_CONST"""
content3 = """from testdir import TEST_CONST
test3=TEST_CONST"""
content4 = """from testdir import foo
test4=foo"""
with get_codebase_session(tmpdir=tmpdir, files={"testdir/test1.py": content1, "testdir/__init__.py": content2, "test3.py": content3, "test4.py": content4}) as codebase:
file1: SourceFile = codebase.get_file("testdir/test1.py")
file2: SourceFile = codebase.get_file("testdir/__init__.py")
file3: SourceFile = codebase.get_file("test3.py")
symb = file1.get_symbol("TEST_CONST")
test = file2.get_symbol("test")
test3 = file3.get_symbol("test3")
test3_import = file3.get_import("TEST_CONST")
assert len(symb.usages) == 3
assert symb.symbol_usages == [test, test3, test3_import]
🎉 This PR is included in version 0.37.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
No description provided.