From dec1d2e8fca998dd2cd15f3f374e321fcb0fb8ac Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 14 Jul 2025 17:54:58 +0100 Subject: [PATCH] ZeroDivisionError for `complex` too --- .../ty_python_semantic/resources/mdtest/binary/integers.md | 3 +++ crates/ty_python_semantic/src/types/infer.rs | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/binary/integers.md b/crates/ty_python_semantic/resources/mdtest/binary/integers.md index 20e6b4aca9..f2169144cb 100644 --- a/crates/ty_python_semantic/resources/mdtest/binary/integers.md +++ b/crates/ty_python_semantic/resources/mdtest/binary/integers.md @@ -143,6 +143,9 @@ bool(1) / False # error: "Cannot divide object of type `float` by zero" reveal_type(1.0 / 0) # revealed: int | float +# error: "Cannot divide object of type `complex` by zero" +reveal_type(0j / 0) # revealed: int | float | complex + class MyInt(int): ... # No error for a subclass of int diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 1248fe7316..d29b053ab4 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -6444,7 +6444,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { true } Type::NominalInstance(instance) - if matches!(instance.class.known(self.db()), Some(KnownClass::Float)) => + if matches!( + instance.class.known(self.db()), + Some(KnownClass::Float | KnownClass::Complex) + ) => { false }