Hello,
Some time ago I started working on adding support for typing **kwargs with TypedDict in python/mypy. I talked with Robert Underwood and he suggested I send a note to Finos community to look for people who would like to cooperate on introducing this change.
Here’s some background on the issue:
With PEP484 type hints were introduced to python. During execution type hints are ignored, but static type checkers like mypy/pyright/pytype/pyre can analyse the code and raise type errors. Static type checking is really useful, especially when projects grow in terms of number of contributors or lines of code.
At the moment, typing **kwargs works as follows:
def foo(**kwargs: int): …
which means that each keyword argument should be of type int.
However, in the codebases that already exists it is often the case that **kwargs have different types. This makes introducing type hints to already existing code bases really cumbersome (something I encountered while adding type hints to urllib3’s codebase). It would be much better to be able to type **kwargs using a TypedDict so that different keywords could have different types. The issue is also described in https://github.com/python/mypy/issues/4441. The feature would be really useful and is anticipated by a large number of users. I also opened the conversation of python’s typing-sig mailing list and got positive replies about this feature.
I’ve already created a PR with logic for mypy to implement this feature: https://github.com/python/mypy/pull/10576.
However, in order for this to work, a new special form – Expand - would have to be introduced to python’s typing and typing_extensions modules (as propsed in the comment in the PR linked above). In order for this to happen a PEP would have to be written and approved.
I am very enthusiastic about this change and would appreciate help in pushing this forward.
Please let me know if someone from Finos community would like to help me with that.
Best regards,
Franek