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

called code side effect #3620

Open
RemiCardona opened this issue May 13, 2020 · 1 comment
Open

called code side effect #3620

RemiCardona opened this issue May 13, 2020 · 1 comment
Labels
Astroid Related to astroid inference Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning

Comments

@RemiCardona
Copy link
Contributor

Spin off from bug #3611 to reduce noise.

Steps to reproduce

  1. fresh virtualenv using python's venv
  2. pip install pylint flask pyserial
  3. grut.py at root of venv directory:
import flask
import serial


def initialize():
    print(flask.Blueprint)
    #print(flask.Config.from_pyfile)
    #print(flask.Config.from_json)
    try:
        serial.Serial()
    except serial.SerialException as exc:
        if isinstance(exc.strerror, str) and "could not open port" in exc.strerror:
            print(exc)
            return
        raise
$ pylint -E grut.py
************ Module grut
grut.py:12:70: E1135: Value 'exc.strerror' doesn't support membership test (unsupported-membership-test)
  1. in grut.py, uncomment the 2nd or 3rd print() instead of the 1st one
  2. error goes away

Open questions

  1. I'm not sure what the "correct" pylint behavior should be. To me, OSError.strerror is a str so the membership test is a false negative. It could also be None but the isinstance() gets us in path where we know for sure in is going to be allowed.
  2. The really tricky bug here is that the order of code analysis changes pylint output, which sounds like a real bug.

Useful information (I think…)

  1. serial.SerialException inherits from IOError
  2. IOError is an "alias" (as per the CPython code) of OSError
  3. the flask code which gets pylint confused reraises IOError exceptions with a modified strerror attribute:
  4. the link with bug Ordering of modules on command line affects reported errors #3611 was that I found this bug through different module names on the command line, managed to narrow it down to 2 files and then reduced it to a single test case file

pylint --version output

$ pylint --version
pylint 2.5.2
astroid 2.4.1
Python 3.7.7 (default, Apr 22 2020, 23:22:50) 
[GCC 9.3.0]
@Pierre-Sassoulas
Copy link
Member

I can reproduce this, but I think it's because in flask.Config.from_pyfile there is e.strerror = "Unable to load configuration file (%s)" % e.strerror so astroid start inferring that strerror is a str. The thing is we infer thing based on code that is available, so I'm not sure it's a bug.

@Pierre-Sassoulas Pierre-Sassoulas added Astroid Related to astroid Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling inference labels Feb 20, 2021
@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Astroid Related to astroid inference Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning
Projects
None yet
Development

No branches or pull requests

2 participants