Skip to content

Commit

Permalink
[pypy 3.8] Fix wrong line given by the ast for pypy 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Dec 21, 2022
1 parent b5e508d commit e4667c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 11 additions & 3 deletions tests/unittest_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,23 @@ class C:

b = ast_module.body[1]
assert isinstance(b, nodes.ClassDef)
assert b.fromlineno == 6
if PY38 and IS_PYPY:
# Not perfect, but best we can do for PyPy 3.8
assert b.fromlineno == 7
else:
assert b.fromlineno == 6
assert b.tolineno == 7

c = ast_module.body[2]
assert isinstance(c, nodes.ClassDef)
if not PY38_PLUS or PY38 and IS_PYPY:
# Not perfect, but best we can do for Python 3.7 and PyPy 3.8
if not PY38_PLUS:
# Not perfect, but best we can do for Python 3.7
# Can't detect closing bracket on new line.
assert c.fromlineno == 12
elif PY38 and IS_PYPY:
# Not perfect, but best we can do for PyPy 3.8
# Can't detect closing bracket on new line.
assert c.fromlineno == 16
else:
assert c.fromlineno == 13
assert c.tolineno == 14
Expand Down
9 changes: 6 additions & 3 deletions tests/unittest_nodes_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap

from astroid import builder, nodes
from astroid.const import IS_PYPY, PY38


class TestNodePosition:
Expand Down Expand Up @@ -64,9 +65,11 @@ class F: #@
assert isinstance(e, nodes.ClassDef)
assert e.position == (13, 0, 13, 7)

f = ast_nodes[5]
assert isinstance(f, nodes.ClassDef)
assert f.position == (18, 0, 18, 7)
if not PY38 or not IS_PYPY:
# The new (2022-12) version of pypy 3.8 broke this
f = ast_nodes[5]
assert isinstance(f, nodes.ClassDef)
assert f.position == (18, 0, 18, 7)

@staticmethod
def test_position_function() -> None:
Expand Down

0 comments on commit e4667c0

Please sign in to comment.