Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

False positive no-member when wrapping dataclasses field #9972

Open
Quexington opened this issue Sep 25, 2024 · 2 comments
Open

False positive no-member when wrapping dataclasses field #9972

Quexington opened this issue Sep 25, 2024 · 2 comments
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling

Comments

@Quexington
Copy link

Quexington commented Sep 25, 2024

Bug description

If I want to alias/wrap a field for a dataclass, then pylint thinks that the members of the dataclass at that point are actually Field objects (at least when checking for no-member). Here's a minimal example:

from dataclasses import dataclass, field

def field_alias(**kwargs):
    # do some stuff analyzing the args

    # The following ignore is "fine" because it only needs to happen in one spot
    return field(**kwargs)  # pylint: disable=invalid-field-call

class ObjectWSubField:
    sub_field: int

@dataclass(frozen=True)
class Temp:
    the_object: ObjectWSubField = field_alias(type=ObjectWSubField)

    def some_method(self):
        # no-member error thrown here and I don't want to throw in an ignore at every spot
        print(self.the_object.sub_field)

Configuration

No response

Command used

pylint a.py

Pylint output

a.py:15:14: E1101: Instance of 'Field' has no 'sub_field' member (no-member)

Expected behavior

No error throw because object is correctly identified as the type it is hinted as

Pylint version

pylint 3.2.6
astroid 3.2.4
Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun  6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]

OS / Environment

Windows 11

Additional dependencies

No response

@Quexington Quexington added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 25, 2024
@alexjircan
Copy link

I have the same issue too :(

@alexjircan
Copy link

It is similar to #4813

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling
Projects
None yet
Development

No branches or pull requests

2 participants