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

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

Open
epignatelli opened this issue Nov 26, 2020 · 3 comments
Open
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation

Comments

@epignatelli
Copy link

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
Copy link
Contributor

hippo91 commented Nov 29, 2020

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

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Nov 29, 2020
@epignatelli
Copy link
Author

epignatelli commented Nov 30, 2020

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
Copy link
Contributor

hippo91 commented Dec 1, 2020

@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.

@Pierre-Sassoulas Pierre-Sassoulas added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

No branches or pull requests

3 participants