Comments (12)
I also found this recently. After some debugging I found the source: https://github.com/PyCQA/pylint/blob/35254c29eb3a0f1c7847cfcb3451501a4180373d/pylint/checkers/variables.py#L1430
In short, if an import is found, only the first part (so e.g. os
) is used for inferred, so that for all other checkers it seems, that import os
was used, instead of os.path
. Not sure if this can be changed easily
from pylint.
Original comment by Andrew Carman (BitBucket: carmandrew, GitHub: @carmandrew?):
This example doesn't fail, but it seems like it should still report that you're not explicitly importing the module you need:
import os.path
print(os.name)
from pylint.
Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):
see http://www.logilab.org/ticket/6646 from the historic tracker
from pylint.
Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):
@carmandrew I fail to see why a warning should be issued in your os.path/os.name case.
#!python
import os.path
add os
to the namespace, so everything is fine. Beside if you don't use os.path anywhere, in which case you're right that a warning would be worth it.
This deserves another ticket though.
from pylint.
Original comment by Andrew Carman (BitBucket: carmandrew, GitHub: @carmandrew?):
Yea, you're right about the os path/name example.
from pylint.
I tried to run pylint 1.9.5 (python2.7) on files with
#!python
import xml.sax.handler
print xml.sax.handler
print xml.sax.saxutils
and
#!python
import os.path
print os.name
no AttributeError s.
Maybe we can close the issue?
from pylint.
@gyermolenko You need to run python
over those files and you'll see a AttributeError: module 'xml.sax' has no attribute 'saxutils'
error. I think this still needs to be fixed.
from pylint.
This still exists in 2.9.0:
five.py
import xml.sax.handler
print(xml.sax.handler)
print(xml.sax.saxutils)
pylint five.py:
------------------------------------
Your code has been rated at 10.00/10
python3 five.py:
<module 'xml.sax.handler' from '/usr/lib/python3.8/xml/sax/handler.py'>
Traceback (most recent call last):
File "c.py", line 3, in <module>
print(xml.sax.saxutils)
AttributeError: module 'xml.sax' has no attribute 'saxutils'
from pylint.
This seems promising @kasium. Do you want to handle the oldest issue still opened ? 😄 I don't know the scope of this either. You can dig a little and just report your finding if this happens to be bigger than what you're prepared to do.
from pylint.
@Pierre-Sassoulas so my first investigation is not the root cause.
As far as I could track down the issue, if a submodule is loaded, the parent is loaded as well, so that a member check like os.path
can succeed. However. since the whole os
module is loaded, checks like os.name
will succeed as well.
Instead of loading the whole os
module if a child is requested, we maybe just want to return a wrapper, which only let's checks for os.path
succeed but not os.name
. Not sure, how complicated this will be
from pylint.
if a submodule is loaded,
Do you mean by astroid or pylint ? Could you point to the specific code doing the loading ?
from pylint.
Re-visiting old issues. Reproduced this with
# test.py
import xml.sax.handler
print(xml.sax.handler)
print(xml.sax.saxutils)
pylint test.py
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 0.00/10, +10.00)
while Python output is
python test.py
<module 'xml.sax.handler' from '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/xml/sax/handler.py'>
Traceback (most recent call last):
File "test.py", line 4, in <module>
print(xml.sax.saxutils)
AttributeError: module 'xml.sax' has no attribute 'saxutils'
from pylint.
Related Issues (20)
- [Feature Request] new lint rule to require a comment #. (HashtagDot) (or #/, new line) at end each python block. And new lint rule for declaring variables to have #declare or #var comment. HOT 5
- Dublicate code wrong behavor. HOT 1
- Can't update functional test refs HOT 5
- False positive E0601: used-before-assignment in try and while block
- [Feature] new lint rule to require "new line" at end each code block. HOT 1
- Pylint does not discover a NoReturn method in certain cases to avoid "inconsistent-return-statements" HOT 3
- False positive for `use-yield-from` for generators yielding from iterators
- pylint crashing with `concurrent.futures.process.BrokenProcessPool` HOT 3
- E0606: detect validation done in external function HOT 6
- Crash ``Building error when trying to create ast representation of module 'aws_cp.__init__'`` HOT 1
- Crash ``Building error when trying to create ast representation of module 'aws_cp.aws'``
- Crash ``Building error when trying to create ast representation of module 'aws_cp.app'``
- pylint cannot find third-party packages in virtual environment HOT 3
- False Positive W0143-comparison-with-callable when using derived property descriptors
- Documentation about `class-const` needs to be updated.
- PEP 695: Type Parameter Syntax HOT 1
- pylint not finding the tox.ini config HOT 12
- [not-an-iterable] FP for attribute used in comprehension but guarded in if test HOT 2
- PyTest FixtureRequest
- Feature Request: Have multiple types for a naming-style HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pylint.