Mypy contribution as a GS employee

7 views
Skip to first unread message

Magiera, Franek

unread,
Sep 27, 2021, 9:09:43 AM9/27/21
to comm...@finos.org

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

 




Your Personal Data: We may collect and process information about you that may be subject to data protection laws. For more information about how we use and disclose your personal data, how we protect your information, our legal basis to use your information, your rights and who you can contact, please refer to: www.gs.com/privacy-notices
Reply all
Reply to author
Forward
0 new messages