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

Fix return type checkers calls on ellipses functions #5107

Merged
merged 7 commits into from
Oct 6, 2021

Conversation

DanielNoord
Copy link
Collaborator

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature, or an important bug fix, add a What's New entry in
    doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Type of Changes

Type
🐛 Bug fix

Description

Closes #4736

@DanielNoord DanielNoord added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Oct 3, 2021
@coveralls
Copy link

coveralls commented Oct 3, 2021

Pull Request Test Coverage Report for Build 1312511792

  • 3 of 3 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 93.115%

Totals Coverage Status
Change from base Build 1309340922: 0.001%
Covered Lines: 13402
Relevant Lines: 14393

💛 - Coveralls

pylint/checkers/classes.py Outdated Show resolved Hide resolved
Comment on lines 2306 to 2307
@staticmethod
def _function_body_is_ellipsis(node: nodes.FunctionDef) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about moving this method to checkers/utils.py?

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be in astroid's FunctionDef instead ?

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be in astroid's FunctionDef instead ?

Though about this some more. I'm not sure we should move these kinds of helper functions to astroid. astroid only really deals with the ast and inference, everything else should be done by pylint.

By the same logic I believe it might have been wrong to move is_sys_guard and is_typing_guard to astroid in the first place. They don't really belong there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Couldn't it be argued that these methods are part of the inference? In that they give additional information about the specific type of FunctionDef node?
Anyway, I'll leave this up to you and Pierre. I'm fine with either.
If wanted I can also make a PR to re-move is_sys_guard and is_typing_guard to pylint.

Copy link
Member

Choose a reason for hiding this comment

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

Couldn't it be argued that these methods are part of the inference? In that they give additional information about the specific type of FunctionDef node?

True. Personally I would consider this a case of meta inference. We check multiple conditions to decide wether or not to emit a warning. That's that sort of thing pylint does all the time.

One thing to consider with that, it's much easier to iterate (read: fix) such a check in pylint alone than to modify something in astroid + pylint.

What I do consider useful in astroid are helpers like this one pylint-dev/astroid#1169 which helps dealing with the NodeNG tree itself.

Anyway, I'll leave this up to you and Pierre. I'm fine with either.
If wanted I can also make a PR to re-move is_sys_guard and is_typing_guard to pylint.

I would be in favor of it, but let's see what @Pierre-Sassoulas thinks first. Unfortunately, we can't outright remove them now, so we would need to deprecate them first (and remove with astroid 3.0).

Copy link
Member

Choose a reason for hiding this comment

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

Let's wait for this to release astroid 2.8.1 then. My local clone is broken and I need to fix it anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean first release 2.8.1 and afterwards deprecate, or the other way around?

Copy link
Member

Choose a reason for hiding this comment

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

I guess, let's do the deprecation now. I.e. wait with releasing astroid 2.8.1 until it's done.
pylint-dev/astroid#1199

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Opened #5122 to add the guard helper functions back to pylint.

pylint/checkers/classes.py Outdated Show resolved Hide resolved
tests/functional/c/class_protocol_ellipsis.py Show resolved Hide resolved
DanielNoord and others added 3 commits October 5, 2021 08:35
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Comment on lines 2 to 3
The "invalid-*-returned" messages shouldn't be emitted for stub functions
Original issue: https://github.com/PyCQA/pylint/issues/4736"""
Copy link
Member

Choose a reason for hiding this comment

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

Can you move these just before the class definition? Someone might add additional test cases later on. That way at least the general docstring will stay up to date.

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.

This PR could be merged after the last comment is addressed and the merge conflict is resolved.

@DanielNoord
Copy link
Collaborator Author

Should be good to go now!

@DanielNoord DanielNoord added this to the 2.12.0 milestone Oct 6, 2021
@cdce8p cdce8p merged commit 8843fc9 into pylint-dev:main Oct 6, 2021
@DanielNoord DanielNoord deleted the return-type-checkers branch October 6, 2021 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

invalid-*-returned false positives in stubs
4 participants