-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make Mypy & JSON models friends #18
base: master
Are you sure you want to change the base?
Conversation
This package looks useful for supporting Mypy generics and reducing redundant args to constructors. https://github.com/ilevkivskyi/typing_inspect i.e. you specify the generic types and the rest is automatic. |
http://mypy-lang.blogspot.com/2019/03/extending-mypy-with-plugins.html -> "Bundled plugins for standard library", describes how a plugin to mypy is used to add virtual typed methods to a class. This is basically the same problem we have in jsonmodels with respect to the model constructors. |
Related work: jazzband#165 |
from mypy.plugin import Plugin, AttributeContext, FunctionContext | ||
from mypy.types import Type as MypyType | ||
|
||
class JSONModelsPlugin(Plugin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool beans 👀
This is some investigation work for making jsonmodel play nice with Mypy.
At the moment:
This is incomplete of course, but the progress is good.
It may be possible to make
ListField
accept a generics type and to eliminate this new duplication of code with theListField
constructor.It seems unlikely that there is a way of explaining to Mypy that model constructors accept keyword arguments which correspond to the names of the model's fields. In this case manually adding a
__init__()
method with the correct types would work too.The
run_mypy.sh
script can be used to put some of the code through mypy.