-
-
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
Typing for ./pylint
, batch 1
#4954
Typing for ./pylint
, batch 1
#4954
Conversation
e365ef6
to
4bcff3e
Compare
I would suggest to wait until after at least #4940 is merged. |
pylint/testutils/output_line.py
Outdated
if isinstance(other, Message): | ||
if self.confidence and other.confidence: | ||
return super().__eq__(other) | ||
return self[:-1] == other[:-1] | ||
return self[:-1] == other[:-1] # type: ignore |
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.
I could not get this to work... Perhaps somebody else wants to take a look at this issue and how to solve it!
Tests are failing on the fact that |
We could wait until the 23rd of December 2021 and drop python 3.6 before adding this typing and removing the |
I'll do that when I get back to my computer. Need to wait for #4940 anyway. |
Pull Request Test Coverage Report for Build 1269333255
💛 - Coveralls |
Any idea why the docs build is failing? Should I add |
Better to guard the |
There are some |
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.
Thanks for your work, but tbh this was really difficult to review. It would be better if you could limit typing changes to much smaller PRs in the future.
One thing that stood out to me was Union[BufferedReader, BytesIO, TextIO]
. It might be better to use a common base class where possible. Something like IOBase
. I annotated it a bunch of times, haven't checked it in details though.
--
One last comment. To make the review process a bit easier, I would appreciate if you don't resolve any of the conversations. I won't be able to find comments otherwise. If you agree, simply add a 👍🏻 and change the code, I'll later go through and resolve them. If you like to start a conversation on a resolved item, please unresolve it.
pylint/checkers/similar.py
Outdated
def append_stream( | ||
self, | ||
streamid: str, | ||
stream: Union[BufferedReader, BytesIO, TextIO], |
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.
Can we use IOBase
here?
pylint/checkers/similar.py
Outdated
"""append a file to search for similarities""" | ||
if encoding is None: | ||
readlines = stream.readlines | ||
readlines: Union[Callable[..., Union[str, bytes]], Any] = stream.readlines |
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.
Why add an annotation at all?
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.
I thought adding typing would be better so we can start moving to adding more mypy flags such as --disallow-untyped-defs
etc.
I can add a type: ignore
if you want, but personally I like how Any
typings serve as a visual reminder that something is left to be done and allow searching for them within the project directory to create a "typing to-do list".
pylint/utils/utils.py
Outdated
stream: Union[BufferedReader, BytesIO, TextIO], | ||
encoding: str, | ||
errors: str = "strict", | ||
) -> Union[latin_1_StreamReader, utf_8_StreamReader, cp1252_StreamReader]: |
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.
Can't you use a base class here? codecs.StreamReader
?
tests/test_self.py
Outdated
@@ -120,11 +120,11 @@ def _display(self, layout: EvaluationSection) -> None: | |||
pass | |||
|
|||
@property | |||
def out(self) -> StringIO: | |||
def out(self) -> Union[TextIO, StringIO, None]: # type: ignore # mypy doesn't seem to recognize properties |
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.
Properties are usually not an issue for mypy.
IOBase
?
tests/test_self.py
Outdated
@property # type: ignore # mypy doesn't seem to recognize properties | ||
def linter(self) -> Optional[PyLinter]: # type: ignore # See comments above |
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.
Same here with the type: ignore
comments
tests/utils/unittest_ast_walker.py
Outdated
@@ -42,7 +42,7 @@ def test_check_messages(self) -> None: | |||
linter = self.MockLinter( | |||
{"first-message": True, "second-message": False, "third-message": True} | |||
) | |||
walker = ASTWalker(linter) | |||
walker = ASTWalker(linter) # type: ignore # Can't import MockLinter. This needs a refactor |
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.
The issue is that MockLinter
doesn't extend PyLinter
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.
Yes, but I also can't type MockLinter
here. What do you want me to do?
I'm truly sorry for making this PR too large. I got a bit carried away when working and forgot to keep a close eye on how truly large this PR had become. If you want I can still split it up based on the three directories and created individual PR's based on your feedback? I'm working on incorporating all of your feedback. One of the issues I ran into is that I'm sorry for resolving the conversation prematurely. I was used to resolving after incorporating feedback but I can see how this is unhelpful for you. I appreciate the effort you took to still review this PR instead of dismissing it because of its size (which I have seen happen in other projects). Thank you! |
I haven't taken a look at all the review comments yet. Only want to answer some of your questions now.
In general smaller PRs might be better. Don't know though if directory bases is the best approach. Although I know it will be more work, I would think of it in related topics. Just to name some examples:
To be honest with you, I haven't checked it in detail if it would work / where it might not. (There were just too many changes.)
It's nothing personal. With so many different conversations I just felt that otherwise I couldn't follow it properly.
I can understand why it sometimes happens. Most maintainers, I would guess, don't know every inch of their code of the top of their head. So it takes a lot of mental energy to go through it if at all. |
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.
Thanks ! This uncovered so many things that ideally we'd have to refactor, it's definitely a step in the right direction.
All checkers inherit from a baseclass which has a ``stats`` attribute. This attribute has a fairly unmanagable type, but the current typing includes all variations of the attribute. Other changes not directly related to ``self.stats`` are due to ``mypy`` warnings. This incorporate the feedback received in pylint-dev#4954
All checkers inherit from a baseclass which has a ``stats`` attribute. This attribute has a fairly unmanageable type, but the current typing includes all variations of the attribute. Other changes not directly related to ``self.stats`` are due to ``mypy``warnings. This incorporate the feedback received in pylint-dev#4954
All checkers inherit from a baseclass which has a ``stats`` attribute. This attribute has a fairly unmanageable type, but the current typing includes all variations of the attribute. Other changes not directly related to ``self.stats`` are due to ``mypy``warnings. This incorporate the feedback received in pylint-dev#4954
* Add typing to all calls to ``self.stats`` All checkers inherit from a baseclass which has a ``stats`` attribute. This attribute has a fairly unmanageable type, but the current typing includes all variations of the attribute. Other changes not directly related to ``self.stats`` are due to ``mypy``warnings. This incorporate the feedback received in #4954 * Add ``CheckerStatistic`` class to ``pylint/typing`` * Guard `typing.Counter` import Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
8a4ac63
to
e5a9146
Compare
f9b4ee0
to
d8bc481
Compare
b562f3e
to
6c8f111
Compare
6c8f111
to
6309d21
Compare
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.
👍
Type of Changes
Description
Similar to #4950 but now for
./pylint
, going directory for directory.For this PR I would like to do 3 directories:
./pylint/utils
./pylint/testutils
./pylint/reporters