Pylint: Incorrect no-member when using contextlib.ExitStack under Python 3.6

Created on 25 Sep 2019  路  6Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. Write the following reproducer out to reproducer.py:
from contextlib import ExitStack

with ExitStack() as stack:
    stack.enter_context(object())
  1. Under Python 3.6, run pylint reproducer.py

(Note that reproducer.py does raise an exception, but it does so _within_ enter_context, so the method does exist.)

Current behavior

# pylint reproducer.py 
<snip>
example.py:4:4: E1101: Instance of 'AbstractContextManager' has no 'enter_context' member (no-member)
<snip>

Note that this behaviour does not exhibit on Python 3.7 (I haven't tried any other Python versions), and we only started seeing it when astroid moved to 2.3.0.

Expected behavior

No no-member warning emitted.

pylint --version output

pylint 2.4.1
astroid 2.3.0
Python 3.6.8 (default, Aug 20 2019, 17:12:48)
[GCC 8.3.0]

(But I also saw it with pylint 2.3.0 and astroid 2.3.0.)

bug topic-inference

All 6 comments

Thanks, I can reproduce it with 3.6.* as well.

This does not happen when using astroid 2.2.5. When stepping up to 2.3.0, it starts to show this error message

I am unable to "just" revert to astroid < 2.3 because then I run into #3022 :-(

So right now this issue appears to have no workaround.

So right now this issue appears to have no workaround.

I had to:

  1. Hold back astroid to <2.3 to work around this issue.
  2. Hold back pylint to <2.4 to avoid it needing astroid 2.3 (#3022).

This got my CI green again.

Any word on when this will be fixed @PCManticore?

This issue has disappeared for me after upgrading from pylint 2.4.4/astroid 2.3.3 to pylint 2.5.3/astroid 2.4.2. I don't see an obvious related fix mentioned in the changelog, but hey, an unexpected fix is still a fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pylint-bot picture pylint-bot  路  3Comments

pylint-bot picture pylint-bot  路  3Comments

thanatos picture thanatos  路  3Comments

GergelyKalmar picture GergelyKalmar  路  3Comments

DevynCJohnson picture DevynCJohnson  路  3Comments