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

E1101: Class 'strerror' has no 'lower' member (no-member) #2553

Closed
DervishD opened this issue Oct 14, 2018 · 2 comments · Fixed by pythoninja/adarklib#29, thermondo/stanley#208 or ChrisRBe/PP-P2P-Parser#85
Labels

Comments

@DervishD
Copy link

DervishD commented Oct 14, 2018

Steps to reproduce

  1. Run pylint --enable=all test.py where test.py is the file below
""" Simpler code to reproduce error. """
import os
import errno
def main():
    """."""
    try:
        raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), 'filename')
    except OSError as exc:
        if exc.strerror is not None:
            print(exc.strerror.lower())

main()

Current behavior

pylint outputs the following for the file above:

************* Module test
test.py:10:18: E1101: Class 'strerror' has no 'lower' member (no-member)

------------------------------------------------------------------
Your code has been rated at 4.44/10

Expected behavior

It should give no errors, because strerror is a string object and as such it has lower(). I don't know why pylint doesn't know that, because strerror is a standard member for OSError exceptions, I'm just curious. I can disable the check, of course, but the code is not wrong, IMHO.

So, the expected output is:

------------------------------------------------------------------
Your code has been rated at 4.44/10

pylint --version output

pylint 2.1.1
astroid 2.1.0-dev
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]

Happens in latest stable, too, but I installed the prerelease just in case.

@PCManticore
Copy link
Contributor

Thanks for the report. pylint doesn't know that strerror is a string, because at the time we build the AST for builtin exceptions, strerror is a member descriptor. For pylint to know that, we'll need to expand the inference engine to look for strerror and similar members, after which we can build the correct types for this members: https://github.com/PyCQA/astroid/blob/master/astroid/interpreter/objectmodel.py#L604

@DervishD
Copy link
Author

Thanks A LOT for the detailed information!

I'll keep an eye on this, then. At first I thought it was impossible to infer that strerror was a string, so I would have to live with this limitation (which is not a big deal anyway), but looks like it is solvable, probably.

Again, thanks :) If more information is needed from me, don't hesitate to ask :)

PCManticore added a commit that referenced this issue Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment