Skip to content

Ignore global variables to avoid confusion with the type aliases #14

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 1 commit into from
Jun 28, 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
13 changes: 0 additions & 13 deletions auto_typing_final/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,9 @@ def find_definitions_in_scope_grouped_by_name(root: SgNode) -> dict[str, list[Sg
return definition_map


def find_definitions_in_global_scope(root: SgNode) -> dict[str, list[SgNode]]:
global_statement_identifiers = defaultdict(list)
for global_statement in root.find_all(kind="global_statement"):
for identifier in find_identifiers_in_children(global_statement):
global_statement_identifiers[identifier.text()].append(global_statement)

return {
identifier: (global_statement_identifiers[identifier] + definitions)
for identifier, definitions in find_definitions_in_scope_grouped_by_name(root).items()
}


def find_definitions_in_module(root: SgNode) -> Iterable[list[SgNode]]:
for function in root.find_all(kind="function_definition"):
yield from find_definitions_in_scope_grouped_by_name(function).values()
yield from find_definitions_in_global_scope(root).values()


def has_global_import_with_name(root: SgNode, name: str) -> bool:
Expand Down
17 changes: 5 additions & 12 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def foo():
"""
a = 1
---
a: typing.Final = 1
a = 1
""",
"""
def foo():
Expand All @@ -76,7 +76,7 @@ def foo():
def bar():
a = 3
---
a: typing.Final = 1
a = 1

def foo():
a: typing.Final = 2
Expand All @@ -85,7 +85,7 @@ def bar():
a: typing.Final = 3
""",
"""
a: typing.Final = 1
a = 1

def foo():
global a
Expand Down Expand Up @@ -595,7 +595,7 @@ def test_transform_file_content(case: str) -> None:
a = 1
---
import typing
a: typing.Final = 1
a = 1
""",
"""
import typing
Expand All @@ -607,21 +607,14 @@ def test_transform_file_content(case: str) -> None:
"""
a: typing.Final = 1
---
import typing
a: typing.Final = 1
""",
"""
a: typing.Final = 1
a = 2
---
a = 1
a = 2
""",
"""
a = 1
---
import typing
a: typing.Final = 1
a = 2
""",
],
)
Expand Down