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

FN attribute-defined-outside-init with setattr() #9798

Open
jacobtylerwalls opened this issue Jul 15, 2024 · 0 comments
Open

FN attribute-defined-outside-init with setattr() #9798

jacobtylerwalls opened this issue Jul 15, 2024 · 0 comments
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@jacobtylerwalls
Copy link
Member

Bug description

# pylint: disable=missing-module-docstring, too-few-public-methods
class NoAttributesDefinedInInit:
    """Both assignments should raise."""
    def later(self):
        """Only the first assignment raises."""
        self.a = "a"
        setattr(self, "b", "b")

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
pylint/a.py:6:8: W0201: Attribute 'a' defined outside __init__ (attribute-defined-outside-init)

------------------------------------------------------------------
Your code has been rated at 7.50/10 (previous run: 7.50/10, +0.00)

Expected behavior

Two messages. You shouldn't be able to get around the lint warning by using setattr() (unless the attribute was already defined in __init__().

Pylint version

pylint 3.3.0-dev0
astroid 3.3.0-dev0
Python 3.12.1

OS / Environment

No response

Additional dependencies

No response

@jacobtylerwalls jacobtylerwalls added Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling False Negative 🦋 No message is emitted but something is wrong with the code labels Jul 15, 2024
@DanielNoord DanielNoord added Help wanted 🙏 Outside help would be appreciated, good for new contributors 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 Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

2 participants