Skip to content
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

Fix 3.11 test #1558

Merged
merged 1 commit into from
May 13, 2022
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
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Release date: TBA

Closes #1403

* Fix test for Python ``3.11``. In some instances ``err.__traceback__`` will
be uninferable now.

What's New in astroid 2.11.6?
=============================
Release date: TBA
Expand Down
23 changes: 17 additions & 6 deletions tests/unittest_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import astroid
from astroid import builder, nodes, objects, test_utils, util
from astroid.const import PY311_PLUS
from astroid.exceptions import InferenceError

try:
Expand Down Expand Up @@ -530,7 +531,8 @@ def test():


class ExceptionModelTest(unittest.TestCase):
def test_valueerror_py3(self) -> None:
@staticmethod
def test_valueerror_py3() -> None:
ast_nodes = builder.extract_node(
"""
try:
Expand All @@ -544,12 +546,21 @@ def test_valueerror_py3(self) -> None:
)
assert isinstance(ast_nodes, list)
args = next(ast_nodes[0].infer())
self.assertIsInstance(args, astroid.Tuple)
assert isinstance(args, astroid.Tuple)
tb = next(ast_nodes[1].infer())
self.assertIsInstance(tb, astroid.Instance)
self.assertEqual(tb.name, "traceback")

with self.assertRaises(InferenceError):
# Python 3.11: If 'contextlib' is loaded, '__traceback__'
# could be set inside '__exit__' method in
# which case 'err.__traceback__' will be 'Uninferable'
try:
assert isinstance(tb, astroid.Instance)
assert tb.name == "traceback"
except AssertionError:
if PY311_PLUS:
assert tb == util.Uninferable
else:
raise

with pytest.raises(InferenceError):
next(ast_nodes[2].infer())

def test_syntax_error(self) -> None:
Expand Down