python - PyDev improperly warns of unused import statement -


i've got following python code in module:

import ldap import ldap.sasl x = ldap.version3 y = ldap.sasl.gssapi 

eclipse (with pydev) warns me first import statement unused. it's being used. python apparently implicitly imports parent packages -- find weird, since python prefers explicit, , can't find mention of in documentation. doesn't mean i'm not using first. more odd, if remove last line, pydev claims both of import statements unused. (i think last case bug in pydev.)

so question is, there way turn off warning first line, without turning off warnings unused imports? , i'd rather not pollute code @unusedimport comments.

the right answer here pydev says.

because import ldap.sasl imports ldap, import ldap statement not necessary, , therefore should removed.


as pydev claiming both unused if remove last line… well, that's not best messaging in world, it's not wrong. import ldap unnecessary because have import ldap.sasl. import ldap.sasl unnecessary because never use it. true, if remove import ldap.sasl, import ldap stops being unnecessary, warnings aren't true different version of code, right?


you're right tutorial section on packages doesn't explain @ all, , 2.x reference documentation doesn't directly it.

however, 3.x reference documentation on the import system describes behavior, , gives examples (e.g., see "regular packages" section), , 2.x reference directly refer original package spec, says:

whenever submodule of package loaded, python makes sure package loaded first, loading __init__.py file if necessary. same packages. thus, when statement import sound.effects.echo executed, first ensures sound loaded; ensures sound.effects loaded; , ensure sound.effects.echo loaded (loading if hasn't been loaded before).

also, existing python 2.x implementations things way 3.x documentation , original package spec describe, , it's not people creating brand-new 2.x implementations in future, think can rely on being guarantee.


if want know original rationale, have read ni module python 1.3. (i don't have link it.) if want know why it's still way in 2.7, it's because first radical cleanup in python didn't happen until 3.0. if want know why it's still way in 3.0, , in 3.3 (after import improved , further cleaned up), you'll have read discussions around pep 328, importlib, etc. on python-ideas , python-dev. when there's consensus not change (or when there's little discussion nobody finds necessary call consensus), don't pep or other "paper trail" outside mailing lists. if remember correctly, did come in passing while discussing relative-vs.-absolute import ideas became pep 328, nobody thought problem needed fixed.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -