Skip to content

[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

Merged
merged 11 commits into from
Feb 25, 2025

Conversation

tkfoss
Copy link
Contributor

@tkfoss tkfoss commented Feb 21, 2025

No description provided.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files

@codegen-team
Copy link
Contributor

Overall Assessment:
The changes significantly improve wildcard import handling and symbol resolution in the codebase. The implementation is thorough and well-tested.

Strengths:

  1. Comprehensive test coverage across various wildcard import scenarios
  2. Clean implementation of recursive symbol resolution
  3. Proper handling of nested module structures
  4. Good attention to edge cases like circular imports

Minor Suggestions:

  1. Consider adding docstrings to the new PyFile methods to maintain documentation consistency
  2. The test file has a typo in function name: test_import_wildcard_preserves_import_resultion should be resolution
  3. Consider adding debug logging for complex resolution chains to aid in troubleshooting

Copy link
Contributor

@bagel897 bagel897 left a 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]

@tkfoss tkfoss enabled auto-merge (squash) February 25, 2025 18:27
@tkfoss tkfoss merged commit 997e36f into develop Feb 25, 2025
25 of 27 checks passed
@tkfoss tkfoss deleted the tom-cg-10888-wildcard-resolution-fix branch February 25, 2025 23:12
Copy link
Contributor

🎉 This PR is included in version 0.37.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

5 participants