pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.31k stars 1.14k forks source link

False 'attribute-defined-outside-init' warning for ctypes structs #8300

Open medhefgo opened 1 year ago

medhefgo commented 1 year ago

Bug description

# pylint: disable=missing-docstring,too-few-public-methods

import ctypes

class Test(ctypes.Structure):
    _fields_ = [("member", ctypes.c_uint8)]

test = Test()
test.member = 42
# pylint: disable=attribute-defined-outside-init
test.not_a_member = 24
assert bytes(test) == b"\x2A"

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
/tmp/test.py:11:0: W0201: Attribute 'member' defined outside __init__ (attribute-defined-outside-init)

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

Expected behavior

pylint should not warn about attributes defined outside of __init__ if the type is a ctypes.Structure and the attribute is defined in the _fields_ list.

Pylint version

pylint 2.16.2
astroid 2.14.2
Python 3.10.9 (main, Dec 19 2022, 17:35:49) [GCC 12.2.0]

OS / Environment

Arch Linux

Additional dependencies

No response

jacobtylerwalls commented 3 months ago

Thanks for the report. Will need to discuss in tandem with #9767.