Skip to content

Commit fb31eed

Browse files
authored
Fix 3.11 test (#1558)
Issue with reassigned __traceback__ attribute. In some cases it can be uninferable now. Ref: #1551
1 parent fd102d4 commit fb31eed

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Release date: TBA
2525

2626
Closes #1403
2727

28+
* Fix test for Python ``3.11``. In some instances ``err.__traceback__`` will
29+
be uninferable now.
30+
2831
What's New in astroid 2.11.6?
2932
=============================
3033
Release date: TBA

tests/unittest_object_model.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import astroid
1111
from astroid import builder, nodes, objects, test_utils, util
12+
from astroid.const import PY311_PLUS
1213
from astroid.exceptions import InferenceError
1314

1415
try:
@@ -530,7 +531,8 @@ def test():
530531

531532

532533
class ExceptionModelTest(unittest.TestCase):
533-
def test_valueerror_py3(self) -> None:
534+
@staticmethod
535+
def test_valueerror_py3() -> None:
534536
ast_nodes = builder.extract_node(
535537
"""
536538
try:
@@ -544,12 +546,21 @@ def test_valueerror_py3(self) -> None:
544546
)
545547
assert isinstance(ast_nodes, list)
546548
args = next(ast_nodes[0].infer())
547-
self.assertIsInstance(args, astroid.Tuple)
549+
assert isinstance(args, astroid.Tuple)
548550
tb = next(ast_nodes[1].infer())
549-
self.assertIsInstance(tb, astroid.Instance)
550-
self.assertEqual(tb.name, "traceback")
551-
552-
with self.assertRaises(InferenceError):
551+
# Python 3.11: If 'contextlib' is loaded, '__traceback__'
552+
# could be set inside '__exit__' method in
553+
# which case 'err.__traceback__' will be 'Uninferable'
554+
try:
555+
assert isinstance(tb, astroid.Instance)
556+
assert tb.name == "traceback"
557+
except AssertionError:
558+
if PY311_PLUS:
559+
assert tb == util.Uninferable
560+
else:
561+
raise
562+
563+
with pytest.raises(InferenceError):
553564
next(ast_nodes[2].infer())
554565

555566
def test_syntax_error(self) -> None:

0 commit comments

Comments
 (0)