-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
(feat) Add type annotations checker #10749
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Alvaro Frias <[email protected]>
Signed-off-by: Alvaro Frias <[email protected]>
Signed-off-by: Alvaro Frias <[email protected]>
Signed-off-by: Alvaro Frias <[email protected]>
Signed-off-by: Alvaro Frias <[email protected]>
Signed-off-by: Alvaro Frias <[email protected]>
This comment has been minimized.
This comment has been minimized.
Pierre-Sassoulas
left a comment
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.
Thank you for this PR, this looks pretty refined already.
| with ``--enable=missing-return-type-annotation``. | ||
|
|
||
| The check automatically skips: | ||
|
|
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.
Maybe we can also add function and methods starting with test_ for return-type ? I always found adding -> None in all tests to be rather pointless. But then mypy would disagree and we probably want to agree with mypy. (Btw just gave me an idea of a checker to check that function starting with test_ should not return anything).
| end_col_offset=7, | ||
| ) | ||
| ): | ||
| self.checker.visit_functiondef(node) |
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.
Great tests (probably). Functional tests are a lot easier to review and write (checking the line number in particular which I didn't do here). Those are faster to run though so let's not rewrite everything unless another maintainer thinks we should.
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.
another thing I notice is that many run ci jobs are failing mainly because pylint is running all the checkers included this one and seems to be many tests cases that dont have type annotations how this should be handled ?
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.
We either need to add typing in the code example or disable in the command(s?) used. If there's a generic command it might be less work to add a disable
Signed-off-by: Alvaro Frias <[email protected]>
for more information, see https://pre-commit.ci
Signed-off-by: Alvaro Frias <[email protected]>
β¦nt into feature/require-typeannotation
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