Skip to content

Commit

Permalink
Fix a crash when None participates in a ** expression (#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls authored and Pierre-Sassoulas committed Jul 10, 2022
1 parent 8de1a4e commit 588f3e8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ What's New in astroid 2.12.1?
=============================
Release date: TBA

* Fix a crash when ``None`` (or a value inferred as ``None``) participates in a
``**`` expression.

* Fix a crash involving properties within ``if`` blocks.


Expand Down
2 changes: 2 additions & 0 deletions astroid/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def const_infer_binary_op(self, opnode, operator, other, context, _):
if (
operator == "**"
and isinstance(self, nodes.Const)
and isinstance(self.value, (int, float))
and isinstance(other.value, (int, float))
and (self.value > 1e5 or other.value > 1e5)
):
yield not_implemented
Expand Down
4 changes: 4 additions & 0 deletions tests/unittest_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ def test_uninferable_exponents() -> None:
parsed = extract_node("15 ** 20220609")
assert parsed.inferred() == [Uninferable]

# Test a pathological case (more realistic: None as naive inference result)
parsed = extract_node("None ** 2")
assert parsed.inferred() == [Uninferable]


@pytest.mark.skipif(not PY38_PLUS, reason="needs assignment expressions")
def test_named_expr_inference() -> None:
Expand Down

0 comments on commit 588f3e8

Please sign in to comment.