-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor to remove circular import in utils/reporter/checker #2809
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 to remove circular import in utils/reporter/checker #2809
Conversation
07eab4f to
491c0a2
Compare
|
@PCManticore, this is a follow up for #2654 to removes circular imports in utils/checker/reporter. It's ready for review :) |
PCManticore
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.
@Pierre-Sassoulas I have this on my todo list for reviews, I hope I can get to it this week.
|
@PCManticore, thank you for starting a review, but please do not plan time for this PR this week : I'll focus on #2805 in order to merge it first. It will make the review of this one a lot easier afterward. (There is the same kind of problems, I'll fix them once and rebase.) |
1a2d8f4 to
be9f0eb
Compare
|
Hey @PCManticore, I looked at the reason of the error for the previous push. It seems that a commit makes MyPy suddenly raise a So this PR do not solve every circular import but solving this would take too much time. |
PCManticore
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.
@Pierre-Sassoulas This looks great, thank you for tackling it! The direction is great and left a couple of comments to be addressed before merging this in.
| MSG_TYPES_LONG, | ||
| MSG_TYPES_STATUS, | ||
| ) | ||
| from pylint.message.build_message_definition import build_message_definition |
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 didn't notice this last time, is it possible to move build_message_definition into message_definition itself so we can squash that module with a single exported function?
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 tried but there definitely is a circular import here :
py36/lib/python3.6/site-packages/pylint/checkers/__init__.py:43: in <module>
from pylint.checkers.base_checker import BaseChecker, BaseTokenChecker
py36/lib/python3.6/site-packages/pylint/checkers/base_checker.py:19: in <module>
from pylint.message.message_definition import build_message_definition
py36/lib/python3.6/site-packages/pylint/message/__init__.py:43: in <module>
from pylint.message.message_handler_mix_in import MessagesHandlerMixIn
py36/lib/python3.6/site-packages/pylint/message/message_handler_mix_in.py:24: in <module>
from pylint.message.message_definition import build_message_definition
py36/lib/python3.6/site-packages/pylint/message/message_definition.py:12: in <module>
from pylint.message.message_definition import MessageDefinition
E ImportError: cannot import name 'MessageDefinition'
I wanted to move the message building in BaseChecker to fix this, but the refactor is humongous see : #2844
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.
Oh gotcha, thanks for the extra explanation.
Some constants were package internal but were used by multiple packages. This created circular dependencies. By creating a file for constants we make sure this does not happen because we won't import everything important in this file and every thing else can depend on it.
ReportsHandlerMixIn was importing Nodes from reporter and is probably more suited for the reporter package anyway.
Now that there is no more circular import we can do that.
This permit to have less cross dependency as the utils package does not depend on anything. The checker package still depends on reporter. Also moved classes from __init__ to their own file in reporter.
It turns out there is not that much utils unittests.
MsgStore.get_messages_from_checker => Checker.messages MsgStore.check_checker_consistency => Checker.check_consistency Probably makes more sense this way.
It was 'hidden' in checkers.__init__.py
Co-Authored-By: Pierre-Sassoulas <[email protected]>
be9f0eb to
1b9e006
Compare
There might be code that is used only in test but it's harder to detect.
74e2dba to
fb2edfa
Compare
fb2edfa to
400a060
Compare
|
There is a test failing in the doc, but I don't think |
|
@Pierre-Sassoulas This is definitely coming from |
|
@Pierre-Sassoulas Did a run with this PR locally and it passes the tests. Let's merge it as is since it's good to go. |
Also fixed spelling in C0112 to C0116 messages following the review of pull-request pylint-dev#2036 by Ashley Whetter. See also pylint-dev#2075, pylint-dev#2077, pylint-dev#2262, pylint-dev#2654, pylint-dev#2805, pylint-dev#2809, pylint-dev#2844, pylint-dev#2992 and pylint-dev#3013 for full historical context.
Also fixed spelling in C0112 to C0116 messages following the review of pull-request pylint-dev#2036 by Ashley Whetter. See also pylint-dev#2075, pylint-dev#2077, pylint-dev#2262, pylint-dev#2654, pylint-dev#2805, pylint-dev#2809, pylint-dev#2844, pylint-dev#2992 and pylint-dev#3013 for full historical context.
Also fixed spelling in C0112 to C0116 messages following the review of pull-request pylint-dev#2036 by Ashley Whetter. See also pylint-dev#2075, pylint-dev#2077, pylint-dev#2262, pylint-dev#2654, pylint-dev#2805, pylint-dev#2809, pylint-dev#2844, pylint-dev#2992 and pylint-dev#3013 for full historical context.
Also fixed spelling in C0112 to C0116 messages following the review of pull-request pylint-dev#2036 by Ashley Whetter. See also pylint-dev#2075, pylint-dev#2077, pylint-dev#2262, pylint-dev#2654, pylint-dev#2805, pylint-dev#2809, pylint-dev#2844, pylint-dev#2992 and pylint-dev#3013 for full historical context.
Description
The idea of this PR is to break dependency cycle by having every constant in
pylint/constant.pyand then every package depending onpylint/utils.In order to do this we created a constant.py file, and moved some class from utils to other package (
utils.ReportsHandlerMixIn=>reporter.ReportsHandlerMixIn) so that nothing inpylint.utilsdepends onpylint.checkerorpylint.reporter. We also moved some function to where they made more sense. For example functions handling Checker in MessageStore were moved to the base checker class so they can be called from any instance of checker. Or unit test for checker.utils were moved from unit test for utils to unit test for checker.utils.This permit to remove the two files we had to create in
pylint.utilswith only the smallnormalized_textandWarningScopeinside it, and simplify the code.Type of Changes
| ✓ | 🔨 Refactoring |
Related Issue
Fix problem discussed in #2654 for
normalized_textandWarningScope.