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

[no-meber] Module 'MySQLdb' has no 'ProgrammingError' member #1138

Closed
ghost opened this issue Oct 19, 2016 · 11 comments
Closed

[no-meber] Module 'MySQLdb' has no 'ProgrammingError' member #1138

ghost opened this issue Oct 19, 2016 · 11 comments

Comments

@ghost
Copy link

ghost commented Oct 19, 2016

Steps to reproduce

imort MySQLdb as db
try:
   cur.execute(sql)
except db.ProgrammingError, err:
   logging.error(err)

Current behavior

[no-meber] Module 'MySQLdb' has no 'ProgrammingError' member

Expected behavior

No error occurs, MySQLdb has ProgrammingError attribute actually.

pylint --version output

pylint 1.5.6, 
astroid 1.4.8
Python 2.7.12 (default, Jul 27 2016, 16:11:41) 
[GCC 5.4.0]
@PCManticore
Copy link
Contributor

PCManticore commented Dec 16, 2016

This seems to be an extension package. Pylint cannot easily understand them, providing only two useful tricks you can use:

  • you can pass --extension-pkg-whitelist=MySQLDB to pylint when you execute it. This will force pylint to load your module and try to build a dynamic AST from the live objects. This might not work, depending how that module is structured or might not be desired at all, since it imports a C extension.

  • you can write an astroid brain tip (https://github.com/PyCQA/astroid/tree/master/astroid/brain) for MySQLdb, in which you can provide any object that pylint cannot recognize.

Hope this helps.

@soundlake
Copy link

Unfortunately, --extension-pkg-whitelist=MySQLDB doesn't work for me. pylintrc file with extension-pkg-whitelist=MySQLDB doesn't work either. I've tried MySQLdb, too, but still I have the pylint error.

pylint 1.8.3,
astroid 1.6.2
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516]

@soundlake
Copy link

Also, isn't this duplicated pylint-dev/astroid#56 ?
According to this, the issue should have been fixed already. But apparently, it's not.

According to pylint-dev/astroid#56, adding whitelist by writing an astroid brain tip seems discouraged. But is the policy changed?

@soundlake
Copy link

I couldn't find the reason why extension-pkg-whitelist doesn't work for me, but I found another solution.
unsafe-load-any-extension=yes is the thing.

@PCManticore
Copy link
Contributor

The thing is that unsafe-load-any-extension and extension-pkg-whitelist is basically the same feature, with the caveat that the former will exempt all C extensions, while the latter will exempt only those mentioned that list. It could be that with unsafe-load-any-extension we also load some module that we miss with extension-pkg-whitelist which could explain why one works for you but the other does not.

@soundlake
Copy link

@PCManticore Thx. Apparently, the module name that's recognized by astroid is not MySQLdb, but _mysql. But it doesn't look right. Isn't it supposed to recognize MySQLdb, especially, the target python code imports MySQLdb rather than _mysql directly?

@PCManticore
Copy link
Contributor

@soundlake That happens because MySQLDb has a C extension that it wraps (https://github.com/farcepest/MySQLdb1/blob/master/_mysql.c). extension-pkg-whitelist unfortunately needs the actual C modules to build the AST.

@soundlake
Copy link

@PCManticore Thank you for the explanation. I'm not pond of the situation, but I get the point.

@zspitz
Copy link

zspitz commented Mar 27, 2018

@PCManticore Does the same thing (the name of the C extension must be used with extension-pkg-whitelist instead of the Python package`) happen every time a package wraps a C extension? If not, under what circumstances does this happen?

@PCManticore
Copy link
Contributor

@zspitz yes, the name of the C extension has to be passed to extension-pkg-whitelist whenever a python library wraps it. This is a caveat that I'll hope to address with #1962.

@egpbos
Copy link

egpbos commented Oct 23, 2019

I had the same issue, but extension-pkg-whitelist=MySQLdb works fine for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants