Skip to content

Commit 39f5f24

Browse files
samwgoldmanfacebook-github-bot
authored andcommitted
Factor out completions_mro
Summary: Before, completions_class calculated the mro for a class. To correctly handle super attribute bases, we need to this. Used in next diff. Reviewed By: stroxler Differential Revision: D80887986 fbshipit-source-id: eb6283a653e200851bf3b3e31b851ff6ed8182d5
1 parent b593927 commit 39f5f24

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

pyrefly/lib/alt/attr.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,16 +2082,16 @@ pub struct AttrInfo {
20822082
}
20832083

20842084
impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
2085-
fn completions_class(
2085+
fn completions_mro<T>(
20862086
&self,
2087-
cls: &Class,
2087+
mro: T,
20882088
expected_attribute_name: Option<&Name>,
20892089
res: &mut Vec<AttrInfo>,
2090-
) {
2091-
let mro = self.get_mro_for_class(cls);
2090+
) where
2091+
T: Iterator<Item = &'a Class>,
2092+
{
20922093
let mut seen = SmallSet::new();
2093-
// NOTE: We do not provide completions from object, to avoid noise like __hash__. Maybe we should?
2094-
for c in iter::once(cls).chain(mro.ancestors_no_object().iter().map(|x| x.class_object())) {
2094+
for c in mro {
20952095
match expected_attribute_name {
20962096
None => {
20972097
for fld in c.fields() {
@@ -2123,6 +2123,18 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
21232123
}
21242124
}
21252125

2126+
fn completions_class(
2127+
&self,
2128+
cls: &Class,
2129+
expected_attribute_name: Option<&Name>,
2130+
res: &mut Vec<AttrInfo>,
2131+
) {
2132+
// NOTE: We do not provide completions from object, to avoid noise like __hash__. Maybe we should?
2133+
let mro = self.get_mro_for_class(cls);
2134+
let mro = iter::once(cls).chain(mro.ancestors_no_object().iter().map(|x| x.class_object()));
2135+
self.completions_mro(mro, expected_attribute_name, res)
2136+
}
2137+
21262138
fn completions_class_type(
21272139
&self,
21282140
cls: &ClassType,

0 commit comments

Comments
 (0)