Skip to content

Commit

Permalink
Fixing python 3.12 support
Browse files Browse the repository at this point in the history
PEP-0709 has remove comprehension scopes
and we should ignore them as well

Ref: https://peps.python.org/pep-0709/
Ref: Technologicat/pyan#93
  • Loading branch information
fruch committed Jan 10, 2024
1 parent acb33a5 commit 951c898
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
8 changes: 8 additions & 0 deletions pytest_diff_selector/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ def process(self):
self.defines_edges = defaultdict(list)
super().process()

def analyze_comprehension(self, *args, **kwargs):
# since https://peps.python.org/pep-0709/ introduce in python 3.12
# we don't comprehension in scope, so we can ignore this logic
# locals of comprehension would be available on the parent scope
# and that should be sufficient of this code usage
if sys.version_info < (3, 12):
super().analyze_comprehension(*args, **kwargs)

def visit_FunctionDef(self, node):
super().visit_FunctionDef(node)

Expand Down
19 changes: 19 additions & 0 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,22 @@ def test_func1():
"test_a.py::TestSomething::test_method_C",
"test_a.py::TestSomething::test_method",
} == ret


def test_usage_of_list_comprehension(test_repo):
write_file(
test_repo,
"test_b.py",
"""
def test_func1():
l = [ i for i in range(10) ]
s = { i for i in range(10) }
call_something()
assert False
""",
)
test_repo.run("git add *.py")

ret = run(git_diff="HEAD", root_path=test_repo.workspace)

assert {"test_b.py::test_func1"} == ret

0 comments on commit 951c898

Please sign in to comment.