Skip to content
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 - Burst utils.py into a "utils" and "message" package #2654

Merged
merged 13 commits into from Mar 9, 2019

Conversation

Pierre-Sassoulas
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas commented Dec 18, 2018

utils.py was big enough that is could cause issue. This is done in order to reduce saving time with syntax aware IDE, and also to make finding a piece of code easier for developer. I think this PR could make development on utils.py easier in the future.

@coveralls
Copy link

coveralls commented Dec 18, 2018

Coverage Status

Coverage increased (+0.03%) to 89.742% when pulling 757b2a5 on Pierre-Sassoulas:utils_refactor into b18acac on PyCQA:master.

@Pierre-Sassoulas
Copy link
Member Author

Pierre-Sassoulas commented Jan 8, 2019

Turn out the error came from the very first commit. I thought importing from a package init.py's file is not the same as importing from a file named like the package. I might have to put back everything into the same file because I have no clue how to fix those 3 errors.

@Pierre-Sassoulas
Copy link
Member Author

@PCManticore, do you have any idea why this commit break 3 functional tests ? I sure don't, and I opened this stackoverflow question regarding the problem.

@PCManticore
Copy link
Contributor

@Pierre-Sassoulas It's definitely not related to your changes. I recently reverted some changes in astroid which affects pylint as well. Feel free to ignore them until we sort this out.

@Pierre-Sassoulas
Copy link
Member Author

@PCManticore, thank you for taking the time to answer. I should rebase less or test the master branch more :)

So I guess this pull request is ready, it fails only for the same tests than the master branch.

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the utils_refactor branch 2 times, most recently from c5456c7 to 16c776c Compare January 27, 2019 21:22
@PCManticore
Copy link
Contributor

I've been intending to review this PR, but it's so big that I can't find a big enough chunk of time to do so. I'll try to go over it over the weekend.

@Pierre-Sassoulas
Copy link
Member Author

Pierre-Sassoulas commented Jan 30, 2019

@PCManticore sorry the git diff is very big but it's basically just :

  • copy pasting code from pylint/utils.py to pylint/utils/class_name.py or pylint/utils/utils.py.
  • changing import so it still works like before after the copy paste
  • and then sorting those imports with isort (I could make a PR to include an isort configuration compatible with black in the pre-commit config, in a different PR if you want.).

I hope this help you review this pull request more easily.

@brycepg
Copy link
Contributor

brycepg commented Mar 7, 2019

Since this PR has been here for so long and all the tests pass I'd be ok with this being merged as is but I'd like @PCManticore to do the merging. I think this PR makes utils on the whole easier to read.

Some post-merge thoughts:

  • WarningScope probably doesn't need to be in it's own file
  • _rest_format_section could be in message_handler_mix_in.py
  • If we're not careful we could end up with cyclical imports

Other non refactor thoughts:

  • Why is Message in utils? It would make sense to be in something like pylint/message.py since it's such a central object.
  • wow the way PyLinter uses these mixins is weird

@Pierre-Sassoulas
Copy link
Member Author

Right, @brycepg I had the same idea than you about messages related classes. There is a lot about messages in utils. But, it could (should?) be in a message package. Yesterday I was about to create a message package little by little in order to make this giant PR in small easier step but I did not find the time.

I can take post-merge thought into account pre-merge. :) Let me know what you think.

Btw we DO end up with cyclical import as soon as we want to put checker related function back into the checker package.

(I also agree that the mixins are hard to understand).

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Mar 8, 2019
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Mar 8, 2019
@Pierre-Sassoulas
Copy link
Member Author

My bad, WarningScope was in its own file to prevent circular import. It's longer to fix the circular import than to just let it be as it is, but I could do it later if you think it's important.

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Mar 8, 2019
@Pierre-Sassoulas
Copy link
Member Author

I made a message package with message related class and constant but there was some conflict during rebase of the most recent change in the master branch. I won't have time to fix it today.

Copy link
Contributor

@PCManticore PCManticore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Pierre-Sassoulas Thanks for the ping. Just gave it a quick look and looks pretty amazing, thank you so much. Left a bunch of small comments, do you plan to add anything else or is the PR ready to go in? If so, we can merge it as soon as possible.

import textwrap


def normalize_text(text, line_len=80, indent=""):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to have a module just for this function, is there a way to move it somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used in a lot of places and I think there is a circular import problem (Like for WarningScope). It's probably possible to fix, but that require some design.

pylint/utils/pylint_ast_walker.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
@@ -0,0 +1,376 @@
# -*- coding: utf-8 -*-
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels odd to have an utils.py inside an utils package, but I don't have a better suggestion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This permit to change the from pylint import utils to from pylint.utils import utils, AstWalker, ... and the class can be imported one by one while still using the utils.function_name() for functions. It makes some change elsewhere less painful. Ideally every utils function would be in a semantically significant module or package but there is a lot of those utility functions...

@Pierre-Sassoulas
Copy link
Member Author

@PCManticore I made the requested change for the discussion I resolved, and I pushed a rebased version for review. There is two unresolved discussions (about the utils.utils.py file and normalize_text.py). I can implements the solution if you have an idea to make those better.

@Pierre-Sassoulas Pierre-Sassoulas changed the title Refactor - Burst utils.py into a "utils" package Refactor - Burst utils.py into a "utils" and "message" package Mar 8, 2019
@PCManticore PCManticore merged commit 5073ebd into pylint-dev:master Mar 9, 2019
PCManticore pushed a commit that referenced this pull request Mar 9, 2019
PCManticore pushed a commit that referenced this pull request Mar 9, 2019
There is a lot of Message related class in Utils
this warrant the creation of a new package.

See also review for burst utils.py into a package here:
#2654 (comment)
PCManticore pushed a commit that referenced this pull request Mar 9, 2019
@PCManticore
Copy link
Contributor

@Pierre-Sassoulas Thank you so much for this cleanup! I don't have any strong opinions about utils.utils and normalize_text but those can be handled in a separate PR, no need to keep this one waiting for that.

@Pierre-Sassoulas Pierre-Sassoulas deleted the utils_refactor branch March 9, 2019 11:07
@Pierre-Sassoulas Pierre-Sassoulas restored the utils_refactor branch March 21, 2019 19:01
@Pierre-Sassoulas Pierre-Sassoulas deleted the utils_refactor branch March 21, 2019 19:01
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Aug 4, 2019
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.
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Aug 19, 2019
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.
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Sep 10, 2019
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.
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this pull request Sep 10, 2019
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.
PCManticore pushed a commit that referenced this pull request Sep 10, 2019
Also fixed spelling in C0112 to C0116 messages following the review
of pull-request #2036 by Ashley Whetter.

See also #2075, #2077, #2262, #2654, #2805, #2809, #2844, #2992
and #3013 for full historical context.
Anthchirp added a commit to Anthchirp/pylint-django-feedstock that referenced this pull request Nov 2, 2020
this is due to pylint-dev/pylint#2654 moving symbols
into different places.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants