Skip to content

Commit 1760fd6

Browse files
committed
[ty] Fix attribute access on intersection types
1 parent 7d0c8e0 commit 1760fd6

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

crates/ty_python_semantic/resources/mdtest/annotations/callable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def f_okay(c: Callable[[], None]):
398398
c.__qualname__ = "my_callable"
399399

400400
result = getattr_static(c, "__qualname__")
401-
reveal_type(result) # revealed: Never
401+
reveal_type(result) # revealed: property
402402
if isinstance(result, property) and result.fset:
403403
c.__qualname__ = "my_callable" # okay
404404
```

crates/ty_python_semantic/src/types.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,19 +3309,14 @@ impl<'db> Type<'db> {
33093309
let name_str = name.as_str();
33103310

33113311
match self {
3312-
Type::Union(union) => union
3313-
.map_with_boundness(db, |elem| {
3314-
elem.member_lookup_with_policy(db, name_str.into(), policy)
3315-
.place
3316-
})
3317-
.into(),
3312+
Type::Union(union) => union.map_with_boundness_and_qualifiers(db, |elem| {
3313+
elem.member_lookup_with_policy(db, name_str.into(), policy)
3314+
}),
33183315

33193316
Type::Intersection(intersection) => intersection
3320-
.map_with_boundness(db, |elem| {
3317+
.map_with_boundness_and_qualifiers(db, |elem| {
33213318
elem.member_lookup_with_policy(db, name_str.into(), policy)
3322-
.place
3323-
})
3324-
.into(),
3319+
}),
33253320

33263321
Type::Dynamic(..) | Type::Never => Place::bound(self).into(),
33273322

@@ -9743,21 +9738,20 @@ impl<'db> IntersectionType<'db> {
97439738
let mut builder = IntersectionBuilder::new(db);
97449739
let mut qualifiers = TypeQualifiers::empty();
97459740

9746-
let mut any_unbound = false;
9747-
let mut any_possibly_unbound = false;
9741+
let mut all_unbound = true;
9742+
let mut any_definitely_bound = false;
97489743
for ty in self.positive_elements_or_object(db) {
97499744
let PlaceAndQualifiers {
97509745
place: member,
97519746
qualifiers: new_qualifiers,
97529747
} = transform_fn(&ty);
97539748
qualifiers |= new_qualifiers;
97549749
match member {
9755-
Place::Unbound => {
9756-
any_unbound = true;
9757-
}
9750+
Place::Unbound => {}
97589751
Place::Type(ty_member, member_boundness) => {
9759-
if member_boundness == Boundness::PossiblyUnbound {
9760-
any_possibly_unbound = true;
9752+
all_unbound = false;
9753+
if member_boundness == Boundness::Bound {
9754+
any_definitely_bound = true;
97619755
}
97629756

97639757
builder = builder.add_positive(ty_member);
@@ -9766,15 +9760,15 @@ impl<'db> IntersectionType<'db> {
97669760
}
97679761

97689762
PlaceAndQualifiers {
9769-
place: if any_unbound {
9763+
place: if all_unbound {
97709764
Place::Unbound
97719765
} else {
97729766
Place::Type(
97739767
builder.build(),
9774-
if any_possibly_unbound {
9775-
Boundness::PossiblyUnbound
9776-
} else {
9768+
if any_definitely_bound {
97779769
Boundness::Bound
9770+
} else {
9771+
Boundness::PossiblyUnbound
97789772
},
97799773
)
97809774
},

0 commit comments

Comments
 (0)