-
Notifications
You must be signed in to change notification settings - Fork 287
fix LSP - typing.NamedTuple tooltip is not informative #2844 #2846
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -698,10 +698,11 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { | |
| }; | ||
| let hint = None; // discard hint | ||
| let class_metadata = self.get_metadata_for_class(cls.class_object()); | ||
| let metaclass_dunder_call = self.get_metaclass_dunder_call(&cls); | ||
| if let Some(ret) = | ||
| self.call_metaclass(&cls, arguments_range, args, keywords, errors, context, hint) | ||
| { | ||
| if let Some(metaclass_dunder_call) = self.get_metaclass_dunder_call(&cls) { | ||
| if let Some(metaclass_dunder_call) = metaclass_dunder_call.clone() { | ||
| if let Some(callee_range) = callee_range | ||
|
Comment on lines
704
to
706
|
||
| && let Some(metaclass) = class_metadata.custom_metaclass() | ||
| { | ||
|
|
@@ -769,7 +770,9 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { | |
| callee_range, | ||
| ); | ||
| } | ||
| self.record_resolved_trace(arguments_range, new_method); | ||
| if metaclass_dunder_call.is_none() { | ||
| self.record_resolved_trace(arguments_range, new_method); | ||
| } | ||
| if self.is_compatible_constructor_return(&ret, cls.class_object()) { | ||
| dunder_new_ret = Some(ret); | ||
| } else if !matches!(ret, Type::Any(AnyStyle::Error | AnyStyle::Implicit)) { | ||
|
|
@@ -824,7 +827,9 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> { | |
| callee_range, | ||
| ); | ||
| } | ||
| self.record_resolved_trace(arguments_range, init_method); | ||
| if !overrides_new && metaclass_dunder_call.is_none() { | ||
| self.record_resolved_trace(arguments_range, init_method); | ||
| } | ||
| } | ||
| if class_metadata.is_pydantic_model() | ||
| && let Some(dataclass) = class_metadata.dataclass_metadata() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
construct_classnow callsget_metaclass_dunder_callunconditionally (and that internally callsget_metadata_for_class), even when the class has no custom metaclass__call__. Since constructor analysis is on a hot path, this adds an extra metadata/member lookup for every class construction. Consider deriving ahas_metaclass_callbool fromcall_metaclass(...)(or returning the resolved__call__type from it) so you only perform the metaclass lookup when it actually exists, or refactorget_metaclass_dunder_callto reuse the already-computedclass_metadata.