Skip to content

Commit

Permalink
Add text for name lookup
Browse files Browse the repository at this point in the history
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
Pierre-Sassoulas and jacobtylerwalls committed Mar 5, 2023
1 parent a87bbbd commit 47a2544
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/test_group_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit 47a2544

Please sign in to comment.