-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Plugin to typecheck attrs-generated classes #4397
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit
Hold shift + click to select a range
005547a
WIP: attrs_plugin_real
euresti ecd0164
Handle untyped attrs
euresti 8f4dbd7
Handle auto_attribs and refactor
euresti 2b55334
WIP: attrs_plugin
euresti 83b008c
WIP: attrs_plugin
euresti 3bc5c11
WIP: attrs_plugin
euresti aa55fe5
WIP: attrs_plugin
euresti 5f897b7
WIP: attrs_plugin
euresti 8867278
Support cmp
euresti cd2aded
WIP: attrs_plugin
euresti 104f9f4
WIP: attrs_plugin
euresti 6856500
WIP: attrs_plugin
euresti 0e359a8
WIP: attr_pyi
euresti ebb9834
WIP: attr_pyi
euresti 001a16a
WIP: attr_pyi
euresti 453c8ae
WIP: attrs_plugin
euresti d26bdb6
WIP: attrs_plugin
euresti e78c040
WIP: attr_pyi
euresti fd1a24b
WIP: attr_pyi
euresti 1680e8f
Support inheritance
euresti 521d215
Fix lint and mypy
euresti 071c0fd
Optionals
euresti 6986547
Never forget Python 3.5
euresti 5d60d99
Sigh
euresti 2284797
Support nested classes
euresti 89f3537
WIP: attrs_plugin
euresti 353319c
Simplify stubs
euresti 72cc0a7
Cleanup tests
euresti e48091f
Get rid of self type.
euresti 2d0f5dd
Comments
euresti f7f6033
Remove magic numbers
euresti 2ff3a19
Cleanup argument pulling
euresti d06bd74
Fix multiple inheritance override
euresti 6fbe81f
Support type=
euresti ccfd6c0
Support frozen=True
euresti 4d9c182
Support @attr.dataclass
euresti 2fc6f5f
Add more tests
euresti d11c138
Cleanup
euresti dd947d2
Support x.default decorator
euresti ce2cac6
Fix issue with classmethods calling cls
euresti d05c364
Get rid of accept. It was causing weird issues
euresti 695b422
Fix Forward Reference Resolution issue
euresti 76fa908
Better types for argument lookups
euresti 405204d
Use type= to set the annotation
euresti 536117f
Add Python2 annotation test
euresti 0fa72a9
Support convert= (Happy New Year!)
euresti 6506d7f
Make cmp methods work with superclasses
euresti 5d16792
Do the correct MRO handling
euresti 9fb4e30
Don't traverse superclasses a 2nd time
euresti 256b446
Support converter
euresti d566806
Remove LastUpdatedOrderedDict
euresti 5b7b290
Move Attribute list into plugin, to avoid touching TypeInfo
euresti b2f075e
Get the argument ordering from the stub instead of hardcoded
euresti f6f2f41
De-flake
euresti 6f60854
Some CR
8000
euresti 7492278
Get rid of called_function helper
euresti 28c7b8d
Add some more tests
euresti aeb01be
Small cleanups
euresti 4fcb5dd
abstract
euresti 1ddb89e
Add more tests.
euresti 5155480
Split get_bool_argument
euresti ff00d73
Fix auto_attribs=True
euresti bc9db4b
Add some python 2 checks
euresti a4f34a8
Warn against sharing one attrib
euresti d7a8e2e
Move helper methods out
euresti 6b86aa2
Merge branch 'master' into attrs_plugin
euresti 8eae273
Fix for new messages
euresti 93f80d6
Cleanup imports
euresti 8cdcbfa
De-flake
euresti 70e25dd
Cleanup comment
euresti fc2b22b
Add warning for using convert
euresti 95e3ac0
Fix bug found when using real stubs
euresti a076957
Move all attrs code to attrs_plugin.py
euresti 3fa9e4f
Refactor code, split into helper methods
euresti cad44bb
Work around circular import
euresti 0240092
Support incremental mode with attrs
euresti c37147d
A little more refactoring
euresti cb795cd
Handle converter in one place
euresti b2b538c
Merge branch 'master' into attrs_plugin
euresti d1e3e0b
Sync typeshed
euresti 6ef4a63
Merge branch 'master' into attrs_plugin
euresti feab654
Fix test
euresti 641230d
Move attrs_plugin to plugins/attrs
euresti bf49a87
Add more incremental tests
euresti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use type= to set the annotation
- Loading branch information
commit 405204d205e24faa990152f120c3872c2b88139d
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -571,6 +571,7 @@ def add_attribute(attr_name: str, attr_type: Optional[Type], default: bool, init | |
for stmt in info.defn.defs.body: | ||
if isinstance(stmt, AssignmentStmt) and isinstance(stmt.lvalues[0], NameExpr): | ||
lhs = stmt.lvalues[0] | ||
assert isinstance(lhs, NameExpr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you move definition of |
||
name = lhs.name | ||
typ = stmt.type | ||
|
||
|
@@ -594,6 +595,10 @@ def add_attribute(attr_name: str, attr_type: Optional[Type], default: bool, init | |
ctx.api.fail('Invalid argument to type', type_arg) | ||
else: | ||
typ = ctx.api.anal_type(un_type) | ||
if typ and isinstance(lhs.node, Var) and not lhs.node.type: | ||
# If there is no annotation, add one. | ||
lhs.node.type = typ | ||
lhs.is_inferred_def = False | ||
|
||
add_attribute(name, typ, attr_has_default, | ||
get_bool_argument(stmt.rvalue, attrib.init), | ||
|
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
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
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.
Shouldn't we require
len(lvalues) == 1
? (Add a test case where this fails.)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.
Oh wow. You can actually declare attrs in multiple ways (which this doesn't currently implement)
@hynek Is the 3rd form I write a correct way to do it. Can 2 names use the same attr?