-
-
Notifications
You must be signed in to change notification settings - Fork 3k
support Callable / callable Protocols in suggest decorator unwarpping #19072
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -230,6 +230,18 @@ def is_implicit_any(typ: Type) -> bool: | |
| return isinstance(typ, AnyType) and not is_explicit_any(typ) | ||
|
|
||
|
|
||
| def _arg_accepts_function(typ: ProperType) -> bool: | ||
| return ( | ||
| # TypeVar / Callable | ||
| isinstance(typ, (TypeVarType, CallableType)) | ||
| or | ||
| # Protocol with __call__ | ||
| isinstance(typ, Instance) | ||
| and typ.type.is_protocol | ||
| and isinstance(typ.type.get_method("__call__"), FuncDef) | ||
| ) | ||
|
|
||
|
|
||
| class SuggestionEngine: | ||
| """Engine for finding call sites and suggesting signatures.""" | ||
|
|
||
|
|
@@ -659,7 +671,7 @@ def extract_from_decorator(self, node: Decorator) -> FuncDef | None: | |
| for ct in typ.items: | ||
| if not ( | ||
| len(ct.arg_types) == 1 | ||
| and isinstance(ct.arg_types[0], TypeVarType) | ||
| and _arg_accepts_function(get_proper_type(ct.arg_types[0])) | ||
| and ct.arg_types[0] == ct.ret_type | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this become
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you mean the probably! but that'd be a separate issue / patch I would imagine
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sorry, misclicked - I meant the == line of course. |
||
| ): | ||
| return None | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.