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
I would expect a static type checker to warn that f1='b' is wrong because the type should be int. There shouldn't be a need to add a type to **kwds since what is accepted can be deduced from how it is used. Note that some_function could be defined in another module and be used in multiple places, thus the "don't repeat yourself" and "separation of concerns" principles apply. Better to have the type for f1 be only in the definition of some_function and not in the **kwds.
This example is similar to #6552, but there it says that it is a duplicate of #4441 which is about typing of **kwds. Why is the solution for this adding a type to **kwds instead of the type checker analyzing how **kwds is used? There are cases in which it is not possible to derive the types based on the use of **kwds. For those certainly makes sense to add a type to it.
Some context as to why I am asking this. I have been developing jsonargparse which can be used for automatically creating complex parsers based on signatures. Figuring out the accepted keyword args and its types based on how **kwds is used, to me seems like a natural feature to expect. jsonargparse 4.10.0.dev2 already supports many cases like this, see AST resolver. I just wonder why static type checkers are not going in this direction.
The text was updated successfully, but these errors were encountered:
As @erictraut explains well in the pyright issue you also opened, this change would require a change in the spec. As this is something that would affect all type checkers and users of Python typing, it shouldn't be discussed on the mypy issue tracker. If you'd like to discuss this, please open an issue at https://github.com/python/typing or on the typing-sig mailing list
Feature
Enable type checking when
**kwds
does not have a type annotation but what it accepts can be deduced based on its use.Pitch
Look at the following example:
I would expect a static type checker to warn that
f1='b'
is wrong because the type should beint
. There shouldn't be a need to add a type to**kwds
since what is accepted can be deduced from how it is used. Note thatsome_function
could be defined in another module and be used in multiple places, thus the "don't repeat yourself" and "separation of concerns" principles apply. Better to have the type forf1
be only in the definition ofsome_function
and not in the**kwds
.This example is similar to #6552, but there it says that it is a duplicate of #4441 which is about typing of
**kwds
. Why is the solution for this adding a type to**kwds
instead of the type checker analyzing how**kwds
is used? There are cases in which it is not possible to derive the types based on the use of**kwds
. For those certainly makes sense to add a type to it.Some context as to why I am asking this. I have been developing jsonargparse which can be used for automatically creating complex parsers based on signatures. Figuring out the accepted keyword args and its types based on how
**kwds
is used, to me seems like a natural feature to expect. jsonargparse 4.10.0.dev2 already supports many cases like this, see AST resolver. I just wonder why static type checkers are not going in this direction.The text was updated successfully, but these errors were encountered: