Skip to content
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
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ What's New in astroid 4.0.0?
============================
Release date: TBA

* Fix crash when comparing invalid dict literal

Closes #2522

* Removed internal functions ``infer_numpy_member``, ``name_looks_like_numpy_member``, and
``attribute_looks_like_numpy_member`` from ``astroid.brain.brain_numpy_utils``.

Expand Down
4 changes: 2 additions & 2 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ def last_child(self):
# TODO: move to util?
@staticmethod
def _to_literal(node: SuccessfulInferenceResult) -> Any:
# Can raise SyntaxError or ValueError from ast.literal_eval
# Can raise SyntaxError, ValueError, or TypeError from ast.literal_eval
# Can raise AttributeError from node.as_string() as not all nodes have a visitor
# Is this the stupidest idea or the simplest idea?
return ast.literal_eval(node.as_string())
Expand Down Expand Up @@ -1887,7 +1887,7 @@ def _do_compare(

try:
left, right = self._to_literal(left), self._to_literal(right)
except (SyntaxError, ValueError, AttributeError):
except (SyntaxError, ValueError, AttributeError, TypeError):
return util.Uninferable

try:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,10 @@ class a: ...
)
assert isinstance(node, nodes.ClassDef)
assert node.name == "a"


def test_regression_infer_dict_literal_comparison_uninferable() -> None:
"""Regression test for issue #2522."""
node = extract_node("{{}}>0")
inferred = next(node.infer())
assert inferred.value == Uninferable
Loading