-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Refactor various typing related issues #4940
Conversation
This adds typing to most calls that visit nodes. All other changes are due to mypy errors resulting from introduction of typing.
This removes some of the `type: ignore` comments in favour of solving the mypy issues these comments were surpressing.
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.
Amazing work, there are a lot of removed type ignore ! Maybe we can even add the mypy option for unnecessary type ignore now ? Regarding the missing type I need to check on a computer later.
Except for two references to node_classes in the changelog this should be the last of them
I have updated the mypy configuration. Outstanding issues:
|
You're right about the python3 checker, I'm going to clean it up, if someone really need to port to python 3 in 2021 that someone can probably suffer to use an older pylint. |
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.
Awesome work you already did here @DanielNoord 🚀
A few points:
- I don't really like the added
pylint: disable=unused-argument
comments. We should use_
instead. - I believe that in the strict mode for mypy even unused arguments should be typed. Those are by far most of my comments.
visit_print
,visit_repr
, andvisit_exec
should get called anymore. Those could be removed. I haven't looked at Remove the python3 porting mode from the codebase #4942 just yet, but will do so next.- We should probably avoid typing generic
list
,dict
, ... . Better to useList[Any]
, ... instead.
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
for more information, see https://pre-commit.ci
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
for more information, see https://pre-commit.ci
Besides open questions from code review, following is needed for this to go forward: |
Pull Request Test Coverage Report for Build 1193364184
💛 - Coveralls |
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.
Amazing work done here. I'm pretty sure being able to use proper typing will prevent crashes in the future.
if is_method_call(func, types, methods) and not is_complex_format_str( | ||
func.bound | ||
if ( | ||
isinstance(func, astroid.BoundMethod) |
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.
Is this equivalent to what we had before ? Maybe this prevent crash we never saw yet ? Thank you, mypy ! 😄
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, it is actually redundant and is_method_call
makes sure that func
is a BoundMethod
. However, this doesn't get recognised by mypy
or any IDE so we need to add this redundant check here.
Perhaps removing the checks from the return statement in is_method_call
and doing if ... return True
might also work. That would remove a duplicate check. However, I am not sure.
Regarding |
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
I have removed Left to-do:
|
With typing added to parts of the code in ``pylint`` it has become useful to import this class so ``pylint`` can access it. See discussion in: pylint-dev/pylint#4940
I have opened pylint-dev/astroid#1160 so that the issue with the typing of |
I did take a look at # old
ops = list(itertools.chain(*ops))
# new
iter_ops: Iterable[Any] = iter(ops)
ops = list(itertools.chain(*iter_ops)) Tbh I think this might be a mypy issue. We can probably leave the fix as you have it now. -- |
@Pierre-Sassoulas already approved my PR for |
Yeah, this is a huge change and need to be merged relatively quickly or we'll get conflict on a lot of other MR. May as well put it in 2.11.0 as I did not finish #4900 and we can't release it yet 😄 |
Is there anything blocking the merge of this PR? Or do you want to wait on the |
With typing added to parts of the code in ``pylint`` it has become useful to import this class so ``pylint`` can access it. See discussion in: pylint-dev/pylint#4940
Type of Changes
Description
This PR has two related aims:
visit_...
andleave_...
calls in the codebaseAs a result of doing the former the number of mypy issues increased so it seemed logical to take another look at some of the open issues (based on comments meant to ignore mypy). I did not add a changelog contribution.
Before merging there are a small number of calls for which I did not find documentation and therefore I could not add the type annotations. I think it would be best to add those before merging this, to make sure this PR catches all calls.
The missing annotations are for:
visit_exec
visit_default
visit_print
visit_repr
visit_package
visit_instance
visit_project
Does any of the maintainers know the nodes passed into these calls? And if so, can you give me a list or add them yourself?