Replies: 1 comment
-
I don't think there's a way to annotate this using today's type system. It's possible to replace the type of a positional parameter using a Your first attempt doesn't work because Your second attempt doesn't work for a couple of reasons. First, you've defined a |
Beta Was this translation helpful? Give feedback.
-
I'm trying to add type annotations to some code that, to keep things DRY, applies a decorator to a number of functions; this decorator "intercepts" the functions' arguments and converts a certain keyword argument from one type to another before passing it on.
Here's a minimal example of what I'm working with, with partial annotations:
Here's my first attempt at annotating this, using
Concatenate
andParamSpec
:Running mypy 1.6.0 with no configuration on this code, using Python 3.11.6 on macOS 14.0, gives me the following errors:
Here's my second attempt at annotations, this time using
Procotol
s with__call__
methods that take**kwargs: Unpack[Kwargs]
:Running
mypy --enable-incomplete-feature=Unpack
on this code gives me the following errors:I also tried a variant of this latter attempt where the bound on
Kwargs
is changed to the classclass KwargsClass(TypedDict): pass
, which has a subclass that adds aflavor: str
attribute, but the only difference that made was getting rid of theVariable "typing.TypedDict" is not valid as a type
error.So, is there a way to properly annotate this, and what is it?
Beta Was this translation helpful? Give feedback.
All reactions