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

False inconsistent-return-statements when using unittest.TestCase.fail #8895

Closed
bdrung opened this issue Jul 28, 2023 · 4 comments
Closed

False inconsistent-return-statements when using unittest.TestCase.fail #8895

bdrung opened this issue Jul 28, 2023 · 4 comments
Labels
Duplicate 🐫 Duplicate of an already existing issue

Comments

@bdrung
Copy link
Contributor

bdrung commented Jul 28, 2023

Bug description

testcase.py:

# pylint: disable=missing-docstring
import unittest


class Test(unittest.TestCase):
    def helper(self, success: bool) -> str:
        if success:
            return "success"
        self.fail("It failed")

Configuration

Default configuration.

Command used

pylint testcase.py

Pylint output

************* Module testcase
testcase.py:6:4: R1710: Either all return statements in a function should return an expression, or none of them should. (inconsistent-return-statements)

Expected behavior

No complaint from pylint.

Pylint version

pylint 2.17.4
astroid 2.15.6
Python 3.11.4 (main, Jun  7 2023, 10:13:09) [GCC 12.3.0]

OS / Environment

Ubuntu 23.10 (mantic)

Additional dependencies

No response

@bdrung bdrung added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Jul 28, 2023
@Pierre-Sassoulas
Copy link
Member

Thank you for opening the issue, this is a duplicate of #4167

@Pierre-Sassoulas Pierre-Sassoulas closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2023
@Pierre-Sassoulas Pierre-Sassoulas added Duplicate 🐫 Duplicate of an already existing issue and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 28, 2023
@bdrung
Copy link
Contributor Author

bdrung commented Jul 28, 2023

Do I read #4167 correctly that this bug can be fixed by adding a NoReturn type hint to unittest.TestCase.fail (and use a pylint version that includes #4304)?

@bdrung
Copy link
Contributor Author

bdrung commented Jul 28, 2023

The typeshed project already declare that unittest.TestCase.fail returns NoReturn: https://github.com/python/typeshed/blob/0d8a6bc2004b7b6d8335e35b017438125c305264/stdlib/unittest/case.pyi#L253

@Pierre-Sassoulas
Copy link
Member

pylint do not take the pyi file into account in 2.17.5, this should be available in 3.0 alpha 7 hen we release it though #4987.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate 🐫 Duplicate of an already existing issue
Projects
None yet
Development

No branches or pull requests

2 participants