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

ignored-modules should turn no-name-in-module-off #223

Closed
pylint-bot opened this issue Apr 30, 2014 · 32 comments
Closed

ignored-modules should turn no-name-in-module-off #223

pylint-bot opened this issue Apr 30, 2014 · 32 comments
Labels

Comments

@pylint-bot
Copy link

Originally reported by: Antony Lee (BitBucket: anntzer, GitHub: @anntzer?)


I believe no-name-in-module is basically the same as no-member (for modules), except that the former triggers at "from ... import" statements. Modules in the "ignore-modules" list should thus be ignored for no-name-in-module too.


@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Don't emit 'no-name-in-module' for ignored modules. Closes issue #223.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


I'm fairly sure this has regressed.

Test case:

#!python

from distutils.util import strtobool
from six.moves import configparser
from six.moves.urllib import parse as urllib_parse
from six.moves.urllib import request as urllib_request


print strtobool
print configparser
print urllib_parse
print urllib_request

pylintrc:

#!dosini

[TYPECHECK]
ignored-modules=distutils,distutils.util,six,six.moves,_MovedItems
ignored-classes=distutils,distutils.util,six,six.moves,_MovedItems

Expected: no errors.

Actual result:

************* Module example
F:  1, 0: Unable to import 'distutils.util' (import-error)
E:  1, 0: No name 'util' in module 'distutils' (no-name-in-module)
F:  2, 0: Unable to import 'six.moves' (import-error)
F:  3, 0: Unable to import 'six.moves.urllib' (import-error)
E:  3, 0: No name 'urllib' in module '_MovedItems' (no-name-in-module)
F:  4, 0: Unable to import 'six.moves.urllib' (import-error)
E:  4, 0: No name 'urllib' in module '_MovedItems' (no-name-in-module)

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


See also: pypa/pip#2048 (comment)

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Maybe a pylintrc problem? I get the following:

#!python

C:  1, 0: Missing module docstring (missing-docstring)
F:  2, 0: Unable to import 'six.moves' (import-error)
F:  3, 0: Unable to import 'six.moves.urllib' (import-error)
F:  4, 0: Unable to import 'six.moves.urllib' (import-error)
W:  1, 0: Unused strtobool imported from distutils.util (unused-import)
W:  2, 0: Unused configparser imported from six.moves (unused-import)
W:  3, 0: Unused parse imported from six.moves.urllib as urllib_parse (unused-import)
W:  4, 0: Unused request imported from six.moves.urllib as urllib_request (unused-import)

Note that ignored-modules works only for no-name-in-module, it doesn't filter out import-errors. Regarding the distutils message, did you use venv? Pylint does have some problem with virtualenvs, see #73/pylint-is-unable-to-import for reference.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


Yes I was in a virtualenv. They replace the distutils namespace with some black-magic code that can't be statically analysed. Regardless, there should be a way to configure pylintrc to avoid lint errors using six.moves.

I see that you didn't copy my example verbatim, since I have the prints there.

I also strongly suspect you don't have six installed.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


For modules that do black magic to add module objects to themselves at runtime (six.moves, distutils under virtualenv), no-name-in-module is equivalent to import-error. I'm fairly certain that the same argument applies as in the original post, when the import error is for a submodule of an ignored-module.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


The py module is another one of these.

Do you want a fresh ticket for this issue?

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


No, I don't have six installed. You can still disable import-errors using disable or do you want something specific for six? Anyway, the problem with distutils should be fixed in the referenced issue (73), not in this one, which was for something totally different.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


@claudiupopa Are you available on freenode?
I'm in #pylint.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


Disabling all import errors for the entire project isn't an agreeable workaround.
My workaround for the moment is an if True block with #pylint:disable=import-errors.
This is quite ugly and makes it hard to sell pylint to the skeptical (AlexGaynor and dstufft in the pip project).

Do you agree on the above assertion that import-error and no-name-in-module is equivalent for these dynamic namespaces?
If so, we can improve the current configuration to work for this use case.
If not, we can add a separate configuration (dynamic_modules ?) for it, but I imagine they will be equal in practice.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Fair enough. I wasn't talking about disabling all the imports, only the ones where Pylint has troubles detecting them. My only concern is that ignored-modules will change semantics, so people will expect that it will filter out only attribute access, not import-errors as well, but it's a small concern in the face of the popularity of the framework.

@pylint-bot
Copy link
Author

Original comment by Buck Evan (BitBucket: bukzor, GitHub: @bukzor?):


@claudiupopa For the sake of clarity, you are agreeing that we should expand the contract of ignored_modules to include import-errors of sub-packages?

I can probably work this up this weekend.
Afterwards, I would move to add six.moves,py,distutils to the default list.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Yes, sorry if I'm unclear.

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Fix issue #223 (ignored_modules should apply to import errors too). The fix will ignore import errors caused by attempting to import any name which is or is a subpackage of a module listed in ignored_modules.

@pylint-bot
Copy link
Author

Original comment by Ivan Smirnov (BitBucket: aldanor, GitHub: @aldanor?):


@PCManticore Is setting ignore-modules supposed to get rid of import-error?

I was getting this kind of errors:

E:  7, 0: No name 'path' in module 'py' (no-name-in-module)
F:  7, 0: Unable to import 'py.path' (import-error)
F: 10, 0: Unable to import 'six.moves' (import-error)
E: 17,15: Module 'py' has no 'path' member (no-member)
E: 20,15: Module 'py' has no 'path' member (no-member)
E: 64,23: Module 'py' has no 'path' member (no-member)
E: 66,17: Module 'py' has no 'path' member (no-member)

Then I've put six and py in ignored-modules:

ignored-modules=py,py.path,six,six.moves

Which seemed to get rid of no-member but not import-error:

F:  7, 0: Unable to import 'py.path' (import-error)
F: 10, 0: Unable to import 'six.moves' (import-error)

Is this intended behaviour or a bug? (astroid 1.3.6, pylint 1.4.4)

@pylint-bot
Copy link
Author

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore):


Yes, ignore-modules can be used to get rid of import-error. The problem is that the fix wasn't officially released into a new pylint version, so pylint 1.4.4 still doesn't have it. It's in the repo, I'm planning to finish Python 3.5 support and some other fixes in the next two weeks and then I'll do a new 1.5 release.

@pylint-bot
Copy link
Author

Original comment by Ivan Smirnov (BitBucket: aldanor, GitHub: @aldanor?):


Great to know, thanks a lot! Looking forward to 1.5 then.

@glennmatthews
Copy link
Contributor

This seems to still be an issue in 1.5.6. Am I missing something?

@bukzor
Copy link
Contributor

bukzor commented Jun 26, 2016

It works for me. Please give us a reproduction.

http://sscce.org

On Sat, Jun 25, 2016, 18:18 Glenn Matthews [email protected] wrote:

This seems to still be an issue in 1.5.6. Am I missing something?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#223 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAnFSJEDl-H3Dq0eioXIegdUlxJ06yB3ks5qPdN9gaJpZM4I-drc
.

@glennmatthews
Copy link
Contributor

User error on my part (duplicate ignored-modules key in .pylintrc). Looks like this kind of user error will be caught in future by Pylint due to moving to use the newer configparser module (#828) which rejects duplicates by default. Sorry for the noise!

@parkan
Copy link

parkan commented Jul 7, 2016

1.6.0 seems to have broken the use of disable=no-name-in-module:

E:  5, 0: Bad option value 'no-name-in-module' (bad-option-value)

This is the only relevant issue I could find from the release notes; is no-name-in-module now superseded by ignored-modules?

@PCManticore
Copy link
Contributor

I cannot reproduce this, it works fine for me, can you provide more details, please?

@PCManticore
Copy link
Contributor

If you can provide the astroid version, the snippet of code for which this reproduces and how you called pylint, that would be helpful.

@parkan
Copy link

parkan commented Jul 7, 2016

[pylint-repro]% cat test/test.py                              (arkadiy@helium:/tmp/pylint-repro)
import doesnotexist  # pylint: disable=no-name-in-module
[pylint-repro]% pylint --errors-only test                     (arkadiy@helium:/tmp/pylint-repro)
Problem importing module variables.py: No module named functools_lru_cache
Problem importing module variables.pyc: No module named functools_lru_cache
No config file found, using default configuration
************* Module test.test
E:  1, 0: Bad option value 'no-name-in-module' (bad-option-value)
[pylint-repro]% python --version                              (arkadiy@helium:/tmp/pylint-repro)
Python 2.7.9
[pylint-repro]% pylint --version                              (arkadiy@helium:/tmp/pylint-repro)
Problem importing module variables.py: No module named functools_lru_cache
Problem importing module variables.pyc: No module named functools_lru_cache
No config file found, using default configuration
pylint 1.6.0,
astroid 1.4.7
Python 2.7.9 (default, Jan  7 2015, 11:49:12)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]

@parkan
Copy link

parkan commented Jul 7, 2016

Also happens in our travis build here https://travis-ci.org/mediachain/mediachain-client/builds/143118789

@PCManticore
Copy link
Contributor

I figured out the problem and I will issue a release shortly.

@parkan
Copy link

parkan commented Jul 7, 2016

@PCManticore thanks so much for the quick response!

@PCManticore
Copy link
Contributor

@parkan can you check with pylint 1.6.1? It should work not as expected.

@parkan
Copy link

parkan commented Jul 7, 2016

Regression fixed 👍

@Valkyrien04
Copy link

seems to have popped back up as of 1.7.2

severity: 'Error'
message: 'E0401:Unable to import 'six.moves.urllib.parse''
at: '9,1'
source: 'pylint'```

@hutchk
Copy link

hutchk commented Nov 11, 2017

Using 1.7.4 still seeing this problem.

@anderson-dan-w
Copy link

Was seeing this error in pylint=1.6.5, astroid=1.4.9, but found that, in my case:

from six.moves.urllib.parse import urlencode

the fix was:

ignored-modules='six.moves.urllib,six.moves.urllib.parse'

jeffwidman added a commit to dpkp/kafka-python that referenced this issue Oct 24, 2018
`six.moves` is a dynamically-created namespace that doesn't actually
exist and therefore `pylint` can't statically analyze it.

By default, `pylint` is smart enough to realize that and ignore the
import errors.

However, because we vendor it, the location changes to
`kafka.vendor.six.moves` so `pylint` doesn't realize it should be
ignored.

So this explicitly ignores it.

`pylint` documentation of this feature:
http://pylint.pycqa.org/en/1.9/technical_reference/features.html?highlight=ignored-modules#id34

More background:
* pylint-dev/pylint#1640
* pylint-dev/pylint#223
jeffwidman added a commit to dpkp/kafka-python that referenced this issue Oct 24, 2018
`six.moves` is a dynamically-created namespace that doesn't actually
exist and therefore `pylint` can't statically analyze it.

By default, `pylint` is smart enough to realize that and ignore the
import errors.

However, because we vendor it, the location changes to
`kafka.vendor.six.moves` so `pylint` doesn't realize it should be
ignored.

So this explicitly ignores it.

`pylint` documentation of this feature:
http://pylint.pycqa.org/en/1.9/technical_reference/features.html?highlight=ignored-modules#id34

More background:
* pylint-dev/pylint#1640
* pylint-dev/pylint#223
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants