8000 make magic_dunder_attr lookup use get_possible_attribute_bases by yangdanny97 · Pull Request #577 · facebook/pyrefly · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

make magic_dunder_attr lookup use get_possible_attribute_bases #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 18 additions & 17 deletions pyrefly/lib/alt/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,23 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
) -> Option<Type> {
let mut not_found = false;
let mut attr_tys = Vec::new();
self.map_over_union(base, |base| {
match self.lookup_magic_dunder_attr_no_union(base, attr_name) {
let attr_bases = self.get_possible_attribute_bases(base);
for attr_base in attr_bases {
let lookup_result = match attr_base {
None => {
LookupResult::InternalError(InternalError::AttributeBaseUndefined(base.clone()))
}
Some(base) => {
let direct_lookup_result =
self.lookup_magic_dunder_attr(base.clone(), attr_name);
self.lookup_attr_from_base_getattr_fallback(
base,
attr_name,
direct_lookup_result,
)
}
};
match lookup_result {
LookupResult::Found(attr) => attr_tys.push(
self.resolve_get_access(attr, range, errors, context)
.unwrap_or_else(|e| {
Expand All @@ -570,7 +585,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
not_found = true;
}
}
});
}
if not_found {
return None;
}
Expand Down Expand Up @@ -1449,20 +1464,6 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
self.lookup_attr_from_base_getattr_fallback(base, attr_name, direct_lookup_result)
}

// This function is intended as a low-level building block
// Unions or intersections should be handled by callers
fn lookup_magic_dunder_attr_no_union(&self, base: &Type, attr_name: &Name) -> LookupResult {
match self.as_attribute_base_no_union(base.clone()) {
None => {
LookupResult::InternalError(InternalError::AttributeBaseUndefined(base.clone()))
}
Some(base) => {
let direct_lookup_result = self.lookup_magic_dunder_attr(base.clone(), attr_name);
self.lookup_attr_from_base_getattr_fallback(base, attr_name, direct_lookup_result)
}
}
}

// This function is intended as a low-level building block
// Unions or intersections should be handled by callers
fn lookup_attr_no_union(&self, base: &Type, attr_name: &Name) -> LookupResult {
Expand Down
8 changes: 8 additions & 0 deletions pyrefly/lib/test/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ def f(a: int, b: int) -> None:
"#,
);

testcase!(
test_bounded_type_var_comparison,
r#"
def compare[T: int](x: T, y: T) -> bool:
return x > y
"#,
);

testcase!(
test_negative_literals,
r#"
Expand Down
Loading
0