Draft
Conversation
sedwards2009
commented
Apr 16, 2020
sedwards2009
commented
Apr 16, 2020
Author
|
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. |
Author
|
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ListFieldaccept a generics type and to eliminate this new duplication of code with theListFieldconstructor.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.shscript can be used to put some of the code through mypy.