Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def f_okay(c: Callable[[], None]):
c.__qualname__ = "my_callable"

result = getattr_static(c, "__qualname__")
reveal_type(result) # revealed: Never
reveal_type(result) # revealed: property
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly surprised that there was no TODO here. This looks fine?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this looks fine!

if isinstance(result, property) and result.fset:
c.__qualname__ = "my_callable" # okay
```
Expand Down
36 changes: 15 additions & 21 deletions crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3309,19 +3309,14 @@ impl<'db> Type<'db> {
let name_str = name.as_str();

match self {
Type::Union(union) => union
.map_with_boundness(db, |elem| {
elem.member_lookup_with_policy(db, name_str.into(), policy)
.place
})
.into(),
Type::Union(union) => union.map_with_boundness_and_qualifiers(db, |elem| {
elem.member_lookup_with_policy(db, name_str.into(), policy)
}),

Type::Intersection(intersection) => intersection
.map_with_boundness(db, |elem| {
.map_with_boundness_and_qualifiers(db, |elem| {
elem.member_lookup_with_policy(db, name_str.into(), policy)
.place
})
.into(),
}),

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

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

let mut any_unbound = false;
let mut any_possibly_unbound = false;
let mut all_unbound = true;
let mut any_definitely_bound = false;
Comment on lines +9741 to +9742
Copy link
Contributor Author

@sharkdp sharkdp Aug 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation here now follows map_with_boundness just above. It was wrong before (see test change in callable.md).

for ty in self.positive_elements_or_object(db) {
let PlaceAndQualifiers {
place: member,
qualifiers: new_qualifiers,
} = transform_fn(&ty);
qualifiers |= new_qualifiers;
match member {
Place::Unbound => {
any_unbound = true;
}
Place::Unbound => {}
Place::Type(ty_member, member_boundness) => {
if member_boundness == Boundness::PossiblyUnbound {
any_possibly_unbound = true;
all_unbound = false;
if member_boundness == Boundness::Bound {
any_definitely_bound = true;
}
Comment on lines +9753 to 9755
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if member_boundness == Boundness::Bound {
any_definitely_bound = true;
}
any_definitely_bound |= member_boundness == Boundness::Bound;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer what we have in terms of readability. Not sure if it compiles to worse code (probably not?), but this is not a hot code path anyway.


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

PlaceAndQualifiers {
place: if any_unbound {
place: if all_unbound {
Place::Unbound
} else {
Place::Type(
builder.build(),
if any_possibly_unbound {
Boundness::PossiblyUnbound
} else {
if any_definitely_bound {
Boundness::Bound
} else {
Boundness::PossiblyUnbound
},
)
},
Expand Down
Loading