-
-
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
Annotate pylint code with type annotations #2079
Comments
@PCManticore since the person opted to work on this issue has backed off, I would like to work on this issue. |
Hey @sushobhit27 I'm not sure who opted to work on this issue, but feel free to take it! The rough idea of this change would be:
Feel free to send multiple smaller PRs for this, since it might require quite a few changes. I suggest starting just with the public APIs for now, e.g methods and functions that are public and that we also use internally. Probably we can skip the visit methods for now, because we already know the type, but if it helps, we can add annotations for them if we can find more bugs in the |
@PCManticore Agree that multiple smaller PRs will be required for this and starting just with the public APIs for now will be good starting point. |
Before we add too many annotations to pylint, will we get more value out of adding annotations to astroid first? From what I understand of transitioning to a typed codebase, typing modules that are lower in the dependency tree first is a good idea because it makes it easier to correct mistakes later and you have more types available to you in the modules that have the dependency when it comes to typing those. |
Sounds like a good plan to me, @AWhetter ! |
#2338 was merged but I'm not sure if we should close this issue now or after we have annotations for all the pylint code. Probably the latter as it's easier to track progress with an opened issue. |
Sounds good to me. Perhaps we close this once we start getting useful information from mypy, not necessarily when pylint is 100% annotated? |
@AWhetter Definitely. Since that is not measurable enough, I'd say we can close this once we have annotations where it matters. It's important that we now have the setup for running |
@PCManticore @AWhetter I will suggest to do in stages, first annotating functions used across pylint code and then covering checker functions. |
I agree with @sushobhit27:
|
List up to date as of 21/04/2022. Done:
--
--
--
|
Just to give an update here, the typing of most base files is now done. What's left is the typing of all |
With #7448 we have now turned on The only thing left to do is #7115, which can close this issue. Over the coming days/weeks I'll try and see if there is anything in our code that needs to be updated, but for now the typing effort is almost done! |
pylint/extensions/check_docs.py should be renamed, because there is no "pylint/extensions/check_docs.py |
I read an article that said that adding types was important for improving performance in python code. It is number 3 in the article: https://aglowiditsolutions.com/blog/python-optimization/ |
I fear that you misinterpreted this paragraph. a: str = "Hello"
b: str = "World"
a = 1
b = 2
print(a + b) You will see that although we annotated the types for Type annotations have a lot of benefits, but (at least for pure Python, there may be other tools like numba that might help here) increased runtime performance is not one of them. |
If everything were typed correctly it would be possible to compile with Mypyc to get a substantial speed improvement. Unfortunately Astroid is thoroughly type-incorrect, and getting it right would take some work. That effort is complicated by the fact that the existing type-incorrect behavior is considered part of the guaranteed public API. So there are both technical and political obstacles to getting things right. |
Huh ? If something is wrongly typed in astroid we should fix the typing, I don't think there's anyone saying the contrary here. But if we want to change the way it's used for example by replacing an |
Here's an example: if isinstance(stmt, nodes.For):
try:
inferred_iterable = next(stmt.iter.infer(context=context))
except (InferenceError, StopIteration):
yield util.Uninferable
return
|
Since we're on Python 3, we can use annotations for pylint.
The text was updated successfully, but these errors were encountered: