(feat) Add type annotations checker#10749
Conversation
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
This comment has been minimized.
This comment has been minimized.
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Thank you for this PR, this looks pretty refined already.
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
for more information, see https://pre-commit.ci
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
…nt into feature/require-typeannotation
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
…nt into feature/require-typeannotation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10749 +/- ##
==========================================
+ Coverage 95.98% 96.30% +0.32%
==========================================
Files 176 179 +3
Lines 19540 19802 +262
==========================================
+ Hits 18755 19071 +316
+ Misses 785 731 -54
🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
cdce8p
left a comment
There was a problem hiding this comment.
What is the benefit of having this be a pylint check? Most type checkers already implement these and likely do a better job at detecting all edge cases.
|
The reasoning was #3853 (comment)
|
Not sure I agree with it. Adding type annotations only make sense if they are also checked for correctness with a type checker and most type checkers implement checks for it already, in particular mypy and pyright. In the end this is just duplicate code with will need to be maintained. If someone really wants to do it, then I guess an extension is probably fine. Though I don't really think it makes sense pylint. |
|
I wouldn't use it personally but there's 16 upvote for the issue so there seem to be a demand for it. I agree it should be an extension or a plugin though. Concretely @qequ it means it should move from |
Signed-off-by: Alvaro Frias <alvaro.frias@eclypsium.com>
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
Thank you @qequ ! I have a few suggestions
Signed-off-by: Alvaro Frias Garay <alvarofriasgaray@gmail.com>
for more information, see https://pre-commit.ci
Signed-off-by: Alvaro Frias Garay <alvarofriasgaray@gmail.com>
Type of Changes
Description
This PR implements a new type annotation checker for Pylint that helps enforce the presence of type annotations in Python code. As discussed in #3853, type annotations improve code readability and enable better static analysis.
What's New
Two New Convention-Level Checkers
C2901:
missing-return-type-annotationDetects functions and methods without return type annotations.
C2902:
missing-param-type-annotationDetects function/method parameters without type annotations.
Key Features
*args,**kwargs)selfandclsparameters (automatically skipped)__init__methods (return type check skipped)@abstractmethod,@propertydecorators@typing.overloadstub definitionsFuture Enhancements
Following Issue discussion and the Google Python Style Guide model, which requires annotations only for public APIs, it could be added different checks for private/public methods:
Other possible future enhancements can be Variable Annotations, and configurable options in .pylintrc
Closes #3853