New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow adding custom methods to TypedDict #4201
Comments
The initial design has a strong requirement for >>> from mypy_extensions import TypedDict
>>> class TD(TypedDict):
... x: int
... y: int
...
>>> td = TD({'x': 1, 'y': 2})
>>> type(td)
<class 'dict'> therefore, you just can't call any additional methods. I therefore propose to close this, unless we want to re-design it. Maybe we can open an issue at |
Yeah, this is out of scope for |
Hm, but my own class will not have a nature that mypy will know which types are stored under which keys, and to check for totality? Does this mean I will also have to roll out my own mypy plugin to be able to type check such class? |
I mean, ideally, I should be able to specify to |
This is just another request for |
I would like to extend TypedDict with extra abstract methods into, for example, class MyParams, which would then allow that those who will be extending MyParams, will be able to both specify types of values they want to list as params, but also have to implement abstract methods.
Currently, if I do:
A subclass like
Foo = MyParams('Foo', {'a': int})
fails because it seemsMyParams
lost its special power to initialize it in this way. If I use class-based syntax, it works, but methodcompute
is still not available on the instance (nor required to be defined, but this is clear problem because metaclass is not abstract metaclass).The text was updated successfully, but these errors were encountered: