Skip to content

Commit a7ab088

Browse files
Raise when a name is inferred twice with the same context (#2238)
Regression in 082774a.
1 parent 71f81ee commit a7ab088

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

astroid/nodes/node_classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def _get_name_nodes(self):
570570
for child_node in self.get_children():
571571
yield from child_node._get_name_nodes()
572572

573+
@decorators.raise_if_nothing_inferred
573574
@decorators.path_wrapper
574575
def _infer(
575576
self, context: InferenceContext | None = None, **kwargs: Any

tests/test_inference.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,13 @@ def get_context_data(self, **kwargs):
14701470
assert len(results) == 2
14711471
assert all(isinstance(result, nodes.Dict) for result in results)
14721472

1473+
def test_name_repeat_inference(self) -> None:
1474+
node = extract_node("print")
1475+
context = InferenceContext()
1476+
_ = next(node.infer(context=context))
1477+
with pytest.raises(InferenceError):
1478+
next(node.infer(context=context))
1479+
14731480
def test_python25_no_relative_import(self) -> None:
14741481
ast = resources.build_file("data/package/absimport.py")
14751482
self.assertTrue(ast.absolute_import_activated(), True)

0 commit comments

Comments
 (0)