Skip to content

False positive no-member with @contextmanager decorated generators #2567

@ZeeD

Description

@ZeeD

I have this little snippet:

import contextlib

@contextlib.contextmanager
def context_manager():
    try:
        yield
    finally:
        pass

cm = context_manager()
cm.__enter__()
cm.__exit__(None, None, None)

pylint signals the "direct" access to the __enter__ and __exit__ callables as an error:

contextmanaged.py:13:0: E1101: Generator 'generator' has no '__enter__' member (no-member)
contextmanaged.py:14:0: E1101: Generator 'generator' has no '__exit__' member (no-member)

while "uncommon" at least, I think it should not be marked as an error.

> pylint --version
pylint 2.1.1
astroid 2.0.4
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)]

Metadata

Metadata

Labels

False Positive 🦟A message is emitted but nothing is wrong with the code

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions