-
-
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
Add typing to all calls to self.stats
#4973
Conversation
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
Pull Request Test Coverage Report for Build 1235382760
π - Coveralls |
pylint/reporters/multi_reporter.py
Outdated
@@ -95,8 +95,14 @@ def on_set_current_module(self, module: str, filepath: Optional[AnyPath]) -> Non | |||
|
|||
def on_close( | |||
self, | |||
stats: Mapping[Any, Any], | |||
previous_stats: Mapping[Any, Any], | |||
stats: Dict[ |
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 changed this to Dict
instead of Mapping
as its only ever called with self.stats
and using Mapping
gave a Mypy
warning because of an incorrect argument type for one of the calls to on_close
.
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 was thinking about creating a class so the typing is simpler and we can unit test it easily.
pylint/checkers/__init__.py
Outdated
def table_lines_from_stats(stats, old_stats, columns): | ||
def table_lines_from_stats( | ||
stats: Dict[ | ||
str, Union[int, Counter[str], List, Dict[str, Union[int, str, Dict[str, int]]]] |
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 List
included in the type of all stats
comes from https://github.com/PyCQA/pylint/blob/40cc2ffd7887959157aaf469e09585ec2be7f528/pylint/checkers/imports.py#L469
This is then used in https://github.com/PyCQA/pylint/blob/40cc2ffd7887959157aaf469e09585ec2be7f528/pylint/graph.py#L170-L182
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.
Not a full review just yet
tests/pyreverse/test_writer.py
Outdated
@@ -28,7 +28,7 @@ | |||
from unittest.mock import Mock | |||
|
|||
import pytest | |||
from conftest import PyreverseConfig # type: ignore | |||
from conftest import PyreverseConfig # type: ignore #pylint: disable=no-name-in-module |
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.
For some reason the import of conftest
introduced in 2500086 failed the pre-commit
.
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.
Shouldn't this be from pylint.pyrevers.conftest import PyreverseConfig
?
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.
See discussion here: #4950 (comment)
Seems like we can't fix this without a (big) 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.
I still feel like I need to think about this a bit longer. Left some comments nevertheless.
tests/pyreverse/test_writer.py
Outdated
@@ -28,7 +28,7 @@ | |||
from unittest.mock import Mock | |||
|
|||
import pytest | |||
from conftest import PyreverseConfig # type: ignore | |||
from conftest import PyreverseConfig # type: ignore #pylint: disable=no-name-in-module |
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.
Shouldn't this be from pylint.pyrevers.conftest import PyreverseConfig
?
@Pierre-Sassoulas You might want to change the milestone on this (or other PRs). Same goes for #4980 in order for the current typing efforts of you and me not to become double-work. Just to let you know, I didn't plan on opening any new typing PRs before the current ones are all merged. Probably best to work on getting the current ones merged first. Perhaps you could help me with a review of #4980 as it requires quite extensive knowledge of |
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
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.
@Pierre-Sassoulas Would you mind taking a look at this? Overall I think it's good. Haven't checked each type tough.
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 like the new class name, and this cleans up a lot of potential problem too π
Yes, I opened #5010 |
Type of Changes
Description
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 tomypy
warnings.This incorporate the feedback received in #4954