Giter Site home page Giter Site logo

Comments (12)

kasium avatar kasium commented on August 21, 2024 1

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.

pylint-bot avatar pylint-bot commented on August 21, 2024

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.

pylint-bot avatar pylint-bot commented on August 21, 2024

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


see http://www.logilab.org/ticket/6646 from the historic tracker

from pylint.

pylint-bot avatar pylint-bot commented on August 21, 2024

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.

pylint-bot avatar pylint-bot commented on August 21, 2024

Original comment by Andrew Carman (BitBucket: carmandrew, GitHub: @carmandrew?):


Yea, you're right about the os path/name example.

from pylint.

gyermolenko avatar gyermolenko commented on August 21, 2024

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.

PCManticore avatar PCManticore commented on August 21, 2024

@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.

Pierre-Sassoulas avatar Pierre-Sassoulas commented on August 21, 2024

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.

Pierre-Sassoulas avatar Pierre-Sassoulas commented on August 21, 2024

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.

kasium avatar kasium commented on August 21, 2024

@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.

Pierre-Sassoulas avatar Pierre-Sassoulas commented on August 21, 2024

if a submodule is loaded,

Do you mean by astroid or pylint ? Could you point to the specific code doing the loading ?

from pylint.

clavedeluna avatar clavedeluna commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.