diff --git a/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md index 186139e1c3..88718bd914 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md @@ -354,6 +354,8 @@ class C(Generic[T]): @overload def __init__(self: "C[bytes]", x: bytes) -> None: ... @overload + def __init__(self: "C[int]", x: bytes) -> None: ... + @overload def __init__(self, x: int) -> None: ... def __init__(self, x: str | bytes | int) -> None: ... @@ -369,6 +371,10 @@ C[bytes]("string") # error: [no-matching-overload] C[bytes](b"bytes") C[bytes](12) +C[int]("string") # error: [no-matching-overload] +C[int](b"bytes") +C[int](12) + C[None]("string") # error: [no-matching-overload] C[None](b"bytes") # error: [no-matching-overload] C[None](12) diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md index 9d4c0a429d..2bf153b969 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md @@ -290,6 +290,8 @@ class C[T]: @overload def __init__(self: C[bytes], x: bytes) -> None: ... @overload + def __init__(self: C[int], x: bytes) -> None: ... + @overload def __init__(self, x: int) -> None: ... def __init__(self, x: str | bytes | int) -> None: ... @@ -305,6 +307,10 @@ C[bytes]("string") # error: [no-matching-overload] C[bytes](b"bytes") C[bytes](12) +C[int]("string") # error: [no-matching-overload] +C[int](b"bytes") +C[int](12) + C[None]("string") # error: [no-matching-overload] C[None](b"bytes") # error: [no-matching-overload] C[None](12) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index ede7203475..2e65524a94 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4649,24 +4649,14 @@ impl<'db> Type<'db> { } } - fn combine_binding_specialization<'db>( - db: &'db dyn Db, - binding: &CallableBinding<'db>, - ) -> Option> { - binding - .matching_overloads() - .map(|(_, binding)| binding.inherited_specialization()) - .reduce(|acc, specialization| { - combine_specializations(db, acc, specialization) - }) - .flatten() - } - let new_specialization = new_call_outcome .and_then(Result::ok) .as_ref() .and_then(Bindings::single_element) - .and_then(|binding| combine_binding_specialization(db, binding)) + .into_iter() + .flat_map(CallableBinding::matching_overloads) + .next() + .and_then(|(_, binding)| binding.inherited_specialization()) .filter(|specialization| { Some(specialization.generic_context(db)) == generic_context }); @@ -4674,7 +4664,10 @@ impl<'db> Type<'db> { .and_then(Result::ok) .as_ref() .and_then(Bindings::single_element) - .and_then(|binding| combine_binding_specialization(db, binding)) + .into_iter() + .flat_map(CallableBinding::matching_overloads) + .next() + .and_then(|(_, binding)| binding.inherited_specialization()) .filter(|specialization| { Some(specialization.generic_context(db)) == generic_context });