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
mypy plugin support for dataclasses #966
Merged
samuelcolvin
merged 14 commits into
pydantic:master
from
koxudaxi:mypy_plugin_support_for_dataclasses
Nov 14, 2019
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fb109d0
mypy plugin support for dataclassesv
koxudaxi 1898087
fix styles and types
koxudaxi 192187a
- change type-hint for `Config`
koxudaxi 19d49ec
fix broken a reference of a document.
koxudaxi 92eada1
- update unittest
koxudaxi 7e97368
fix a document link
koxudaxi 4652387
Update docs/mypy_plugin.md
koxudaxi 9576bd0
Update docs/mypy_plugin.md
koxudaxi 35302bd
Update docs/mypy_plugin.md
koxudaxi 5068657
remove extra whitespaces on mypy test results
koxudaxi 05ca1ca
fix output file name of mypy test
koxudaxi d036cf0
Update docs/usage/dataclasses.md
koxudaxi e39b8f9
Merge branch 'master' into mypy_plugin_support_for_dataclasses
koxudaxi ff1f630
use TypeVar for DataclassType
koxudaxi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,35 @@ | ||
23: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
samuelcolvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
24: error: Missing named argument "y" for "Model" [call-arg] | ||
25: error: Property "y" defined in "Model" is read-only [misc] | ||
26: error: "Model" does not have orm_mode=True [pydantic-orm] | ||
35: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg] | ||
46: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg] | ||
52: error: Invalid value for "Config.extra" [pydantic-config] | ||
57: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
62: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
73: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment] | ||
76: error: Untyped fields disallowed [pydantic-field] | ||
83: error: Untyped fields disallowed [pydantic-field] | ||
86: error: Missing named argument "a" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "b" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "c" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "d" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "e" for "DefaultTestingModel" [call-arg] | ||
90: error: Name 'Undefined' is not defined [name-defined] | ||
93: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg] | ||
100: error: Missing named argument "y" for "construct" of "Model" [call-arg] | ||
102: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type] | ||
107: error: Argument "x" to "InheritingModel" has incompatible type "str"; expected "int" [arg-type] | ||
108: error: Argument "x" to "Settings" has incompatible type "str"; expected "int" [arg-type] | ||
109: error: Argument "x" to "Model" has incompatible type "str"; expected "int" [arg-type] | ||
126: error: Argument "data" to "Response" has incompatible type "int"; expected "Model" [arg-type] | ||
134: error: Argument "y" to "AliasModel" has incompatible type "int"; expected "str" [arg-type] | ||
140: error: Required dynamic aliases disallowed [pydantic-alias] | ||
144: error: Argument "z" to "DynamicAliasModel" has incompatible type "str"; expected "int" [arg-type] | ||
155: error: Unexpected keyword argument "y" for "DynamicAliasModel2" [call-arg] | ||
162: error: Required dynamic aliases disallowed [pydantic-alias] | ||
180: error: Untyped fields disallowed [pydantic-field] | ||
184: error: Unexpected keyword argument "x" for "AliasGeneratorModel2" [call-arg] | ||
185: error: Unexpected keyword argument "z" for "AliasGeneratorModel2" [call-arg] | ||
188: error: Name 'Missing' is not defined [name-defined] | ||
24: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
25: error: Missing named argument "y" for "Model" [call-arg] | ||
26: error: Property "y" defined in "Model" is read-only [misc] | ||
27: error: "Model" does not have orm_mode=True [pydantic-orm] | ||
36: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg] | ||
47: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg] | ||
53: error: Invalid value for "Config.extra" [pydantic-config] | ||
58: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
63: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
74: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment] | ||
77: error: Untyped fields disallowed [pydantic-field] | ||
84: error: Untyped fields disallowed [pydantic-field] | ||
87: error: Missing named argument "a" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "b" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "c" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "d" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "e" for "DefaultTestingModel" [call-arg] | ||
91: error: Name 'Undefined' is not defined [name-defined] | ||
94: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg] | ||
101: error: Missing named argument "y" for "construct" of "Model" [call-arg] | ||
103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type] | ||
108: error: Argument "x" to "InheritingModel" has incompatible type "str"; expected "int" [arg-type] | ||
109: error: Argument "x" to "Settings" has incompatible type "str"; expected "int" [arg-type] | ||
110: error: Argument "x" to "Model" has incompatible type "str"; expected "int" [arg-type] | ||
127: error: Argument "data" to "Response" has incompatible type "int"; expected "Model" [arg-type] | ||
135: error: Argument "y" to "AliasModel" has incompatible type "int"; expected "str" [arg-type] | ||
141: error: Required dynamic aliases disallowed [pydantic-alias] | ||
145: error: Argument "z" to "DynamicAliasModel" has incompatible type "str"; expected "int" [arg-type] | ||
156: error: Unexpected keyword argument "y" for "DynamicAliasModel2" [call-arg] | ||
163: error: Required dynamic aliases disallowed [pydantic-alias] | ||
181: error: Untyped fields disallowed [pydantic-field] | ||
185: error: Unexpected keyword argument "x" for "AliasGeneratorModel2" [call-arg] | ||
186: error: Unexpected keyword argument "z" for "AliasGeneratorModel2" [call-arg] | ||
189: error: Name 'Missing' is not defined [name-defined] | ||
197: error: Argument "config" to "dataclass" has incompatible type "Dict[<nothing>, <nothing>]"; expected "Optional[Type[BaseConfig]]" [arg-type] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
23: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
24: error: Missing named argument "y" for "Model" [call-arg] | ||
25: error: Property "y" defined in "Model" is read-only [misc] | ||
26: error: "Model" does not have orm_mode=True [pydantic-orm] | ||
35: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg] | ||
46: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg] | ||
52: error: Invalid value for "Config.extra" [pydantic-config] | ||
57: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
62: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
73: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment] | ||
86: error: Missing named argument "a" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "b" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "c" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "d" for "DefaultTestingModel" [call-arg] | ||
86: error: Missing named argument "e" for "DefaultTestingModel" [call-arg] | ||
90: error: Name 'Undefined' is not defined [name-defined] | ||
93: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg] | ||
100: error: Missing named argument "y" for "construct" of "Model" [call-arg] | ||
102: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type] | ||
155: error: Missing named argument "x" for "DynamicAliasModel2" [call-arg] | ||
174: error: unused 'type: ignore' comment | ||
181: error: unused 'type: ignore' comment | ||
188: error: Name 'Missing' is not defined [name-defined] | ||
24: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
25: error: Missing named argument "y" for "Model" [call-arg] | ||
26: error: Property "y" defined in "Model" is read-only [misc] | ||
27: error: "Model" does not have orm_mode=True [pydantic-orm] | ||
36: error: Unexpected keyword argument "x" for "ForbidExtraModel" [call-arg] | ||
47: error: Unexpected keyword argument "x" for "ForbidExtraModel2" [call-arg] | ||
53: error: Invalid value for "Config.extra" [pydantic-config] | ||
58: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
63: error: Invalid value for "Config.orm_mode" [pydantic-config] | ||
74: error: Incompatible types in assignment (expression has type "ellipsis", variable has type "int") [assignment] | ||
87: error: Missing named argument "a" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "b" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "c" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "d" for "DefaultTestingModel" [call-arg] | ||
87: error: Missing named argument "e" for "DefaultTestingModel" [call-arg] | ||
91: error: Name 'Undefined' is not defined [name-defined] | ||
94: error: Missing named argument "undefined" for "UndefinedAnnotationModel" [call-arg] | ||
101: error: Missing named argument "y" for "construct" of "Model" [call-arg] | ||
103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type] | ||
156: error: Missing named argument "x" for "DynamicAliasModel2" [call-arg] | ||
175: error: unused 'type: ignore' comment | ||
182: error: unused 'type: ignore' comment | ||
189: error: Name 'Missing' is not defined [name-defined] | ||
197: error: Argument "config" to "dataclass" has incompatible type "Dict[<nothing>, <nothing>]"; expected "Optional[Type[BaseConfig]]" [arg-type] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
28: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
63: error: Untyped fields disallowed [pydantic-field] | ||
78: error: Argument "x" to "OverrideModel" has incompatible type "float"; expected "int" [arg-type] | ||
29: error: Unexpected keyword argument "z" for "Model" [call-arg] | ||
64: error: Untyped fields disallowed [pydantic-field] | ||
79: error: Argument "x" to "OverrideModel" has incompatible type "float"; expected "int" [arg-type] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
121: error: Unexpected keyword argument "name" for "AddProject" [call-arg] | ||
samuelcolvin marked this conversation as resolved.
Show resolved
Hide resolved
samuelcolvin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
121: error: Unexpected keyword argument "slug" for "AddProject" [call-arg] | ||
121: error: Unexpected keyword argument "description" for "AddProject" [call-arg] |
This file contains 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
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.
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.
Should this use a TypeVar?
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.
Did you expect this?
Also, Did you want to replace other
-> 'DataclassType'
like__init__
?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.
Yeah, that's what I meant, I think it would be better (assuming that is the right signature, which I think it is?).
I don't think the
__init__
signature needs to change, but maybe the_validate_dataclass
one should.(Any other places where
'DataclassType'
is currently used probably should; I believe this is what is done for factory classmethods forBaseModel
-- I don't see why it shouldn't be that way for the dataclasses.)Also, I would recommend using something like
DataclassT
as the name of theTypeVar
, to make it slightly more obvious what's happening, and give itbound=DataclassType
. (The TypeVar forBaseModel
inpydantic.main
is calledModel
; I think that's nice.)