-
Notifications
You must be signed in to change notification settings - Fork 52
[CG-7930] feat: remove unused imports after moving symbol & new api for removing unused symbols #39
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
Changes from all commits
23ea9e5
833c7a8
2542923
abb5bc6
c65b534
7670afa
004cf06
5556510
daf1b75
5da1428
57577ff
32769df
6b7e688
f744bf2
7123cf9
6a31479
4aa7676
682c428
f6290cf
3c33141
62e1176
5ef9f27
624295c
b22c368
fbeb41b
956d3ea
01f2fa1
b209125
6af57d8
c7b4401
310891f
658b010
50d40d9
4e0a66e
13c9ec4
737e555
b07e6f2
af179b5
75dd7dc
589d089
2820313
676ce46
bf7b7d0
6de94d3
77ab8b9
cce834c
dc04179
9f1b9ae
56eceff
48c3ffb
641b0aa
fe36690
d71fca8
a225999
cee50b2
8ca64ff
d2f3414
37664b9
bfbd7b0
ef987af
34cdf58
e429498
440a57f
636034a
609c0b6
fdfe835
36cf065
14595fb
d4fe603
516d9c1
2bd1e4a
2e0449d
ba4b842
ac2c348
547eef0
a03ba1c
ee5a854
2995692
db70491
4abaae0
f55f27c
106111e
6224ca6
df1e801
38aa188
fe2a026
eb38163
73b93a6
1fec4b3
dd54bf9
e36d0b6
d863ad3
4e5f74a
2763872
4f17fba
85a4331
029fcfa
4408ae8
cf24fbd
1332f95
3524117
ef9881e
428b289
37eb5bb
e03e067
2fb7d06
2642cca
2ef105c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,6 +284,55 @@ def get_import_string( | |
else: | ||
return f"from {import_module} import {self.name}" | ||
|
||
@property | ||
def module_name(self) -> str: | ||
"""Gets the module name for this import. | ||
|
||
For 'import x' returns 'x' | ||
For 'from x import y' returns 'x' | ||
For 'from .x import y' returns '.x' | ||
|
||
Returns: | ||
str: The module name for this import. | ||
""" | ||
if self.ts_node.type == "import_from_statement": | ||
module_node = self.ts_node.child_by_field_name("module_name") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rely on self.module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean use self.module instead of the .module_name? it seems to miss some imports then. or should module_name itself be changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's missing imports, that may be a bug in the SDK. Generally we want to use our nodes rather than tree-sitters post-parse |
||
return module_node.text.decode("utf-8") if module_node else "" | ||
return self.ts_node.child_by_field_name("name").text.decode("utf-8") | ||
|
||
def is_from_import(self) -> bool: | ||
"""Determines if this is a from-style import statement. | ||
|
||
Checks if the import uses 'from' syntax (e.g., 'from module import symbol') | ||
rather than direct import syntax (e.g., 'import module'). | ||
|
||
Returns True for imports like: | ||
- from x import y | ||
- from .x import y | ||
- from x import (a, b, c) | ||
- from x import * | ||
|
||
Returns False for: | ||
- import x | ||
- import x as y | ||
|
||
Returns: | ||
bool: True if this is a from-style import, False otherwise. | ||
""" | ||
return self.import_type in [ImportType.NAMED_EXPORT, ImportType.WILDCARD] | ||
|
||
@property | ||
def is_future_import(self) -> bool: | ||
"""Determines if this is a __future__ import. | ||
|
||
Returns True for imports like: | ||
- from __future__ import annotations | ||
|
||
Returns: | ||
bool: True if this is a __future__ import, False otherwise | ||
""" | ||
return self.ts_node.type == "future_import_statement" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use import_type? |
||
|
||
|
||
class PyExternalImportResolver(ExternalImportResolver): | ||
def __init__(self, from_alias: str, to_context: CodebaseGraph) -> None: | ||
|
Uh oh!
There was an error while loading. Please reload this page.