Skip to content

Commit d308a3a

Browse files
committed
Only use first matching constructor
1 parent b5da8ee commit d308a3a

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ class C(Generic[T]):
361361
def __init__(self, x: str | bytes | int) -> None: ...
362362

363363
reveal_type(C("string")) # revealed: C[str]
364-
# TODO: revealed: C[bytes]
365-
reveal_type(C(b"bytes")) # revealed: C[bytes | int]
364+
reveal_type(C(b"bytes")) # revealed: C[bytes]
366365
reveal_type(C(12)) # revealed: C[Unknown]
367366

368367
C[str]("string")

crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ class C[T]:
299299
def __init__(self, x: str | bytes | int) -> None: ...
300300

301301
reveal_type(C("string")) # revealed: C[str]
302-
# TODO: revealed: C[bytes]
303-
reveal_type(C(b"bytes")) # revealed: C[bytes | int]
302+
reveal_type(C(b"bytes")) # revealed: C[bytes]
304303
reveal_type(C(12)) # revealed: C[Unknown]
305304

306305
C[str]("string")

crates/ty_python_semantic/src/types.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4663,32 +4663,25 @@ impl<'db> Type<'db> {
46634663
}
46644664
}
46654665

4666-
fn combine_binding_specialization<'db>(
4667-
db: &'db dyn Db,
4668-
binding: &CallableBinding<'db>,
4669-
) -> Option<Specialization<'db>> {
4670-
binding
4671-
.matching_overloads()
4672-
.map(|(_, binding)| binding.inherited_specialization())
4673-
.reduce(|acc, specialization| {
4674-
combine_specializations(db, acc, specialization)
4675-
})
4676-
.flatten()
4677-
}
4678-
46794666
let new_specialization = new_call_outcome
46804667
.and_then(Result::ok)
46814668
.as_ref()
46824669
.and_then(Bindings::single_element)
4683-
.and_then(|binding| combine_binding_specialization(db, binding))
4670+
.into_iter()
4671+
.flat_map(CallableBinding::matching_overloads)
4672+
.next()
4673+
.and_then(|(_, binding)| binding.inherited_specialization())
46844674
.filter(|specialization| {
46854675
Some(specialization.generic_context(db)) == generic_context
46864676
});
46874677
let init_specialization = init_call_outcome
46884678
.and_then(Result::ok)
46894679
.as_ref()
46904680
.and_then(Bindings::single_element)
4691-
.and_then(|binding| combine_binding_specialization(db, binding))
4681+
.into_iter()
4682+
.flat_map(CallableBinding::matching_overloads)
4683+
.next()
4684+
.and_then(|(_, binding)| binding.inherited_specialization())
46924685
.filter(|specialization| {
46934686
Some(specialization.generic_context(db)) == generic_context
46944687
});

0 commit comments

Comments
 (0)