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

Class definition in conditionals not correctly found #10238

Open
Flamefire opened this issue Feb 20, 2025 · 0 comments
Open

Class definition in conditionals not correctly found #10238

Flamefire opened this issue Feb 20, 2025 · 0 comments
Labels
Control flow Requires control flow understanding Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed

Comments

@Flamefire
Copy link

Bug description

I'm using a conditional type definition: A dataclass for Python 3.9+ and a namedtuple otherwise. Then I'm running PyLint with Python 3.12.

PyLint does not detect the unexpected and missing keyword args for that type.

Input:

# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=too-few-public-methods
import sys
from dataclasses import dataclass

if sys.version_info >= (3, 9):
    @dataclass
    class Foo:
        x: int
        y: int
else:
    class Foo:
        pass


@dataclass
class Bar:
    x: int
    y: int


Foo(X2=1, y=2)
Bar(X2=1, y=2)


This is reduced, the actual fallback uses `Foo = namedtuple('Foo', ('x', 'y'))` but it shouldn't matter as that branch shouldn't be taken at all. Also swapping the branches and condition such that unused one comes first doesn't change the outcome

Configuration

Command used

pylint a.py

Pylint output

************* Module a
/tmp/a.py:24:0: E1123: Unexpected keyword argument 'X2' in constructor call (unexpected-keyword-arg)
/tmp/a.py:24:0: E1120: No value for argument 'x' in constructor call (no-value-for-parameter)

Expected behavior

The same error is shown for Foo and Bar on lines 23 & 24
Bar in the example is only the sanity check for comparison, not relevant to the bug

Pylint version

pylint 3.3.4
asteroid 3.3.8
Python 3.9.18

OS / Environment

No response

Additional dependencies

@Flamefire Flamefire added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Feb 20, 2025
@Pierre-Sassoulas Pierre-Sassoulas added Control flow Requires control flow understanding Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Control flow Requires control flow understanding Needs astroid update Needs an astroid update (probably a release too) before being mergable Needs design proposal 🔒 This is a huge feature, some discussion should happen before a PR is proposed
Projects
None yet
Development

No branches or pull requests

2 participants