You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this example code, decorator adds a keyword-only argument special_kwarg to a decorated function, type hint provided by CustomFunctionProtocol.
When I run mypy for this Python code, there is no error. I see reveal_type(example_function) is also working well.
Type of "example_function" is "CustomFunctionProtocol[(a: int, b: int, c: int), int]" [Pylance]
Revealed type is "typing_test_20241224.CustomFunctionProtocol[[a: builtins.int, b: builtins.int, c: builtins.int], builtins.int]" [Mypy]
However, running pyright will report an error regarding special_kwarg;
typing_test_20241224.py:11:9 - error: Keyword parameter "special_kwarg" cannot appear in signature after ParamSpec args parameter (reportGeneralTypeIssues)
typing_test_20241224.py:18:35 - error: Keyword parameter "special_kwarg" cannot appear in signature after ParamSpec args parameter (reportGeneralTypeIssues)
typing_test_20241224.py:30:20 - information: Type of "example_function" is "CustomFunctionProtocol[(a: int, b: int, c: int), int]"
When I try to use that function on code, VSCode intellisense does not reflect the ParamSpec variable properly, it shows example_function(*args, special_kwarg: str, **kwargs) instead. I installed Mypy type checker, Pylance and Python extensions.
Perhaps showing correct intellisense for generic Protocol's __call__ is not implemented yet. I do not know where to ask or complain this, neither I know how to make this intellisense do the correct behavior, so I am seeking if there is any other way to give a type hint for "kwargs" version of typing.Concatenate.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I wrote a decorator code adds custom keyword-only argument on the function using
typing.Protocol
and generics.In this example code,
decorator
adds a keyword-only argumentspecial_kwarg
to a decorated function, type hint provided byCustomFunctionProtocol
.When I run
mypy
for this Python code, there is no error. I seereveal_type(example_function)
is also working well.However, running
pyright
will report an error regardingspecial_kwarg
;When I try to use that function on code, VSCode intellisense does not reflect the
ParamSpec
variable properly, it showsexample_function(*args, special_kwarg: str, **kwargs)
instead. I installed Mypy type checker, Pylance and Python extensions.Perhaps showing correct intellisense for generic
Protocol
's__call__
is not implemented yet. I do not know where to ask or complain this, neither I know how to make this intellisense do the correct behavior, so I am seeking if there is any other way to give a type hint for "kwargs" version oftyping.Concatenate
.Beta Was this translation helpful? Give feedback.
All reactions