Skip to content

Commit

Permalink
Raise when a name is inferred twice with the same context (pylint-dev…
Browse files Browse the repository at this point in the history
…#2238)

Regression in 082774a.
  • Loading branch information
jacobtylerwalls committed Jul 6, 2023
1 parent 71f81ee commit a7ab088
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def _get_name_nodes(self):
for child_node in self.get_children():
yield from child_node._get_name_nodes()

@decorators.raise_if_nothing_inferred
@decorators.path_wrapper
def _infer(
self, context: InferenceContext | None = None, **kwargs: Any
Expand Down
7 changes: 7 additions & 0 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,13 @@ def get_context_data(self, **kwargs):
assert len(results) == 2
assert all(isinstance(result, nodes.Dict) for result in results)

def test_name_repeat_inference(self) -> None:
node = extract_node("print")
context = InferenceContext()
_ = next(node.infer(context=context))
with pytest.raises(InferenceError):
next(node.infer(context=context))

def test_python25_no_relative_import(self) -> None:
ast = resources.build_file("data/package/absimport.py")
self.assertTrue(ast.absolute_import_activated(), True)
Expand Down

0 comments on commit a7ab088

Please sign in to comment.