From 47a2544cbfacbfcec90b1a0b80ae06710fb9b6b1 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Sun, 5 Mar 2023 22:41:14 +0100 Subject: [PATCH] Add text for name lookup Co-authored-by: Jacob Walls --- tests/test_group_exceptions.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/test_group_exceptions.py b/tests/test_group_exceptions.py index d3a577b658..173c25ed00 100644 --- a/tests/test_group_exceptions.py +++ b/tests/test_group_exceptions.py @@ -5,8 +5,18 @@ import pytest -from astroid import AssignName, ExceptHandler, For, Name, TryExcept, extract_node +from astroid import ( + AssignName, + ExceptHandler, + For, + Name, + TryExcept, + Uninferable, + bases, + extract_node, +) from astroid.const import PY311_PLUS +from astroid.context import InferenceContext from astroid.nodes import Expr, Raise, TryStar @@ -82,3 +92,20 @@ def test_star_exceptions() -> None: final = node.finalbody[0] assert isinstance(final, Expr) assert final.value.args[0].value == 0 + + +@pytest.mark.skipif(not PY311_PLUS, reason="Requires Python 3.11 or higher") +def test_star_exceptions_infer_name() -> None: + trystar = extract_node( + """ +try: + 1/0 +except* ValueError: + pass""" + ) + name = "arbitraryName" + context = InferenceContext() + context.lookupname = name + stmts = bases._infer_stmts([trystar], context) + assert list(stmts) == [Uninferable] + assert context.lookupname == name