diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8fca81a..140de04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: [3.5, 3.6, 3.7, 3.8, 3.9, '3.10', 3.11, 3.12-dev, pypy-3.6] + python-version: [3.8, 3.9, '3.10', 3.11, 3.12-dev] steps: - uses: actions/checkout@v2 diff --git a/executing/_position_node_finder.py b/executing/_position_node_finder.py index 8ca21a6..7a0cca6 100644 --- a/executing/_position_node_finder.py +++ b/executing/_position_node_finder.py @@ -156,6 +156,8 @@ def __init__(self, frame: FrameType, stmts: Set[EnhancedAST], tree: ast.Module, typ=typ, ) + self.result = self.fix_result(self.result, self.instruction(lasti)) + self.known_issues(self.result, self.instruction(lasti)) self.test_for_decorator(self.result, lasti) @@ -213,6 +215,32 @@ def test_for_decorator(self, node: EnhancedAST, index: int) -> None: if sys.version_info < (3, 12): index += 4 + def fix_result( + self, node: EnhancedAST, instruction: dis.Instruction + ) -> EnhancedAST: + if ( + sys.version_info >= (3, 12, 5) + and instruction.opname in ("GET_ITER", "FOR_ITER") + and isinstance(node.parent, ast.For) + and node is node.parent.iter + ): + # node positions have changed in 3.12.5 + # https://github.com/python/cpython/issues/93691 + # `for` calls __iter__ and __next__ during execution, the calling + # expression of these calls was the ast.For node since cpython 3.11 (see test_iter). + # cpython 3.12.5 changed this to the `iter` node of the loop, to make tracebacks easier to read. + # This keeps backward compatibility with older executing versions. + + # there are also cases like: + # + # for a in iter(l): pass + # + # where `iter(l)` would be otherwise the resulting node for the `iter()` call and the __iter__ call of the for implementation. + # keeping the old behaviour makes it possible to distinguish both cases. + + return node.parent + return node + def known_issues(self, node: EnhancedAST, instruction: dis.Instruction) -> None: if instruction.opname in ("COMPARE_OP", "IS_OP", "CONTAINS_OP") and isinstance( node, types_cmp_issue diff --git a/setup.cfg b/setup.cfg index fdf901f..ed446d0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,9 +11,6 @@ classifiers = License :: OSI Approved :: MIT License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.6 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -25,7 +22,7 @@ packages = executing zip_safe = False include_package_data = True setup_requires = setuptools; setuptools_scm[toml] -python_requires = >=3.5 +python_requires = >=3.8 [options.extras_require] tests= diff --git a/tests/test_main.py b/tests/test_main.py index bc015cd..84b1305 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -810,6 +810,9 @@ def test_module_files(self): or 'pyparsing.py' in filename or 'enum' in filename ) + or sys.version_info < (3,11) and ( + 'python.py' in filename + ) ): continue diff --git a/tox.ini b/tox.ini index 3566691..6c68c4e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35,py36,py37,py38,py39,py310,py311,py312,pypy35,pypy36 +envlist = py38,py39,py310,py311,py312,pypy35,pypy36 [testenv] commands = @@ -10,7 +10,7 @@ passenv = ADD_EXECUTING_TESTS EXECUTING_SLOW_TESTS -[testenv:generate_small_sample-py{35,36,37,38,39,310,311}] +[testenv:generate_small_sample-py{38,39,310,311,312}] extras = tests deps = pysource-minimize commands =