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

Use overload to type get_global_option #4978

Merged
merged 5 commits into from
Sep 8, 2021

Conversation

DanielNoord
Copy link
Collaborator

@DanielNoord DanielNoord commented Sep 6, 2021

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Write a good description on what the PR does.

Type of Changes

Type
βœ“ πŸ”¨ Refactoring

Description

The next step in splitting #4954 in more manageable PR's.

I opted to go for overload as it allows us to immediately tell what get_global_option will return or throw an error if it is unspecified.
The globals added to pylint/utils/utils.py could go in pylint/typing but since they won't be used outside of this file I thought it would be best to add them here.

Sorry for making a second PR. The fix turned out to be much easier than anticipated.

@DanielNoord DanielNoord closed this Sep 6, 2021
@DanielNoord DanielNoord reopened this Sep 6, 2021
@coveralls
Copy link

coveralls commented Sep 6, 2021

Pull Request Test Coverage Report for Build 1212335532

  • 15 of 15 (100.0%) changed or added relevant lines in 3 files are covered.
  • 40 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.01%) to 93.112%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/similar.py 6 96.58%
pylint/checkers/classes.py 34 94.75%
Totals Coverage Status
Change from base Build 1206663671: 0.01%
Covered Lines: 13248
Relevant Lines: 14228

πŸ’› - Coveralls

Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

I like this a lot 😍

I also though of overload. That was the reason I wanted a separate PR for it πŸ˜‰
Furthermore the change is quite concise which makes it really easy to review.

pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
@cdce8p cdce8p added this to the 2.11.0 milestone Sep 6, 2021
@cdce8p cdce8p added the Maintenance Discussion or action around maintaining pylint or the dev workflow label Sep 6, 2021
pylint/utils/utils.py Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
pylint/utils/utils.py Outdated Show resolved Hide resolved
DanielNoord and others added 2 commits September 7, 2021 08:54
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
@DanielNoord
Copy link
Collaborator Author

DanielNoord commented Sep 7, 2021

Not really sure about the naming of the type alias and TypeVar. Went with GLOBAL_OPTION_NAMES and GLOBAL_OPTION_RETURN_TYPES respectively, but let me know what you think!

Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

The TypeVar seems to work. It will prevent things like this where the return type doesn't match the default:

@overload
def get_global_option(
    checker: "BaseChecker", option: GLOBAL_OPTION_BOOL, default: Optional[bool] = None
) -> str:
    ...

pylint/utils/utils.py Outdated Show resolved Hide resolved
Copy link
Member

@cdce8p cdce8p left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks @DanielNoord πŸŽ‰

@cdce8p cdce8p merged commit 1e85bb7 into pylint-dev:main Sep 8, 2021
@DanielNoord DanielNoord deleted the typing-global-option branch September 13, 2021 11:24
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