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

using-constant-test triggers on a built-in exception property #9556

Open
holmanb opened this issue Apr 18, 2024 · 0 comments
Open

using-constant-test triggers on a built-in exception property #9556

holmanb opened this issue Apr 18, 2024 · 0 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@holmanb
Copy link

holmanb commented Apr 18, 2024

Bug description

The using-constant-test warning shows up on conditional use of SystemExit's code property. This appears similar to, but not the same as #3484.

Given the following code, run pylint on it. Note the comment.

test_pylint.py

import sys


def test_invalid_W0125():
    """
    This test demonstrates a false positive for W0640.

    Message emitted:
    Using a conditional statement with a constant value

    Description:
    Emitted when a conditional statement (If or ternary if) uses a constant
    value for its test. This might not be what the user intended to do.
    """

    for i in range(5):
        try:
            sys.exit(i)
        except SystemExit as e:

            # pylint incorrectly thinks that the following conditional uses
            # a constant value
            if e.code:
                print(f"sys.exit() called with argument: {e.code}")
            assert e.code == i

Configuration

No response

Command used

pylint test_pylint.py

Pylint output

************* Module test
test.py:23: [W0125(using-constant-test), test_invalid_W0125] Using a conditional statement with a constant value

------------------------------------------------------------------
Your code has been rated at 8.89/10 (previous run: 5.62/10, +3.26)

Expected behavior

No error

Pylint version

pylint 3.0.3
astroid 3.0.2
Python 3.12.2 (main, Apr  2 2024, 18:40:52) [GCC 13.2.0]

OS / Environment

Ubuntu 24.04

Additional dependencies

No response

@holmanb holmanb added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 18, 2024
@DanielNoord DanielNoord added False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 19, 2024
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 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants