Relative Content

Tag Archive for pythonpython-typingmypy

How to pass an untyped dictionary assigned to a variable to a method that expects a TypedDict without mypy complaining?

I would like to pass a dictionary to a method foo that expects a TypedDict without explicitly mentioning the type. When I pass the dictionary directly to the method, everything is good. However, when I assign the dictionary to a variable configs first, mypy complains about incompatible types. Interestingly, PyCharm does not complain about foo(configs) as long as configs contains the correct keys and values. I could add type information to configs at [1] below but wonder if I could improve the typing to make the usage of foo and Params less verbose.