diff --git a/ChangeLog b/ChangeLog index 47e74120e0..23bd762d02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/astroid/protocols.py b/astroid/protocols.py index 6a6523513d..a7f35ea4a6 100644 --- a/astroid/protocols.py +++ b/astroid/protocols.py @@ -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 diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py index dfac90193e..63765a5ea5 100644 --- a/tests/unittest_protocols.py +++ b/tests/unittest_protocols.py @@ -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: