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.26k stars 1.12k forks source link

Attributes added by a decorator are raised as missing members errors #3957

Open epignatelli opened 3 years ago

epignatelli commented 3 years ago

Steps to reproduce

# test.py
import functools
from typing import Callable, NamedTuple

class Module(NamedTuple):
    init: Callable
    apply: Callable

def module(module_maker):
    @functools.wraps(module_maker)
    def fabricate_module(*args, **kwargs):
        init, apply = module_maker(*args, **kwargs)
        return Module(init, apply)
    return fabricate_module

@module
def my_module():
    def my_module_init(x_in):
        return x_in
    def my_module_apply(x_in):
        return x_in
    return my_module_init, my_module_apply

mod = my_module()
INPUT_X = 0.
mod.init(INPUT_X)
mod.apply(0.)
!python test.py
# no errors
!pylint test.py --disable "C0114,C0115,C0116"
# outputs:
# test.py:26:0: E1101: Instance of 'tuple' has no 'init' member (no-member)
# test.py:27:0: E1101: Instance of 'tuple' has no 'apply' member (no-member)

You can also try it at: https://colab.research.google.com/drive/1Jsgd_vVWIjVj7gqWKNsi6pOYNsP6l5uV#scrollTo=BfnN70BAt1Mi

Current behavior

pylint is returning a warning that mod does not have init or apply members.

Expected behavior

I would expect pylint to recognize that mod has an init and apply attribute, and not output those problems

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.6.9 (default, Oct  8 2020, 12:12:24) 
[GCC 8.4.0]
hippo91 commented 3 years ago

@epignatelli thanks for the report. I can reproduce it.

epignatelli commented 3 years ago

Thanks @hippo91! Do you have a roadmap where I can follow the bug-fixing progresses?

Happy to help if you give me an hint where to look at.

hippo91 commented 3 years ago

@epignatelli no we don't have roadmap here. We are just a few volunteers to make pylint work and we are doing it on our free time. I would be great if you could help us. The bug you discovered is probably not the easiest to start with but you can start by trying to make your snippet as simple as possible. You can also look for other issues that are marked contributor friendly.