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

[spelling checker] Use a context manager to access the private dict #6493

Merged
merged 1 commit into from
May 3, 2022

Conversation

Pierre-Sassoulas
Copy link
Member

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

Follow-up to #6491, before #6137

@Pierre-Sassoulas Pierre-Sassoulas added the Maintenance Discussion or action around maintaining pylint or the dev workflow label May 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.0 milestone May 3, 2022
@coveralls
Copy link

coveralls commented May 3, 2022

Pull Request Test Coverage Report for Build 2264351021

  • 0 of 3 (0.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.005%) to 95.177%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pylint/checkers/spelling.py 0 3 0.0%
Files with Coverage Reduction New Missed Lines %
pylint/checkers/spelling.py 2 77.01%
Totals Coverage Status
Change from base Build 2264081008: 0.005%
Covered Lines: 15828
Relevant Lines: 16630

πŸ’› - Coveralls

Comment on lines 273 to 275
self.private_dict_path: str = os.path.expanduser(
self.linter.config.spelling_private_dict_file
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Safe to do because:

>>> import os
>>> os.path.expanduser("")
''

Copy link
Collaborator

@DanielNoord DanielNoord left a comment

Choose a reason for hiding this comment

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

Is there a direct need for self.private_dict_path? It seems like we could use self.linter.config.spelling_private_dict_file directly. The only difficulty is that we would need to do os.path.expanduser when loading the argument. So we would need a new argument type (probably called path).

@@ -267,10 +267,15 @@ class SpellingChecker(BaseTokenChecker):
),
)

def __init__(self, linter: PyLinter):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, linter: PyLinter):
def __init__(self, linter: PyLinter) -> None:

@Pierre-Sassoulas
Copy link
Member Author

The only difficulty is that we would need to do os.path.expanduser when loading the argument. So we would need a new argument type (probably called path).

Having a generic path option that would make ALL options using a path, expand the user path correctly would be a huge win for pylint. There's 7 expandusers call in the codebase, but probably a lot of option where we do not support this yet.

@DanielNoord
Copy link
Collaborator

Having a generic path option that would make ALL options using a path, expand the user path correctly would be a huge win for pylint. There's 7 expandusers call in the codebase, but probably a lot of option where we do not support this yet.

Shouldn't be too difficult to create a new transformer. Do you want to look into this?

@Pierre-Sassoulas
Copy link
Member Author

Pierre-Sassoulas commented May 3, 2022

Do you want to look into this?

Sure.

Regarding the other comment, using the configuration make for rather long unreadable variable name self.linter.config.spelling_private_dict_file, spelling is noise when we're in the spelling checker (but not when we're in the pylint configuration) so I supposed that creating a small var name specific to the checker would clarify the code.

@DanielNoord
Copy link
Collaborator

Do you want to look into this?

Sure.

Regarding the other comment, using the configuration make for rather long unreadable variable name self.linter.config.spelling_private_dict_file, spelling is noise when we're in the spelling checker (but not when we're in the pylint configuration) so I supposed that creating a small var name specific to the checker would clarify the code.

Hm, on the other hand decoupling a setting from the actual underlying setting could create other problems down the line. What if we have the per directory configuration enabled and the underlying Namespace changes? I'd be in favour of the long name (although I do agree it is a bit annoying).

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the fix-consider-using-with-spelling-checker branch from b770192 to b067fee Compare May 3, 2022 14:16
@Pierre-Sassoulas Pierre-Sassoulas merged commit cadfdb2 into main May 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas deleted the fix-consider-using-with-spelling-checker branch May 3, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance Discussion or action around maintaining pylint or the dev workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants