#440 Code analysis: wrong 'undefined variable from import' error

1.2.6
closed-fixed
Editor (491)
5
2007-03-25
2007-02-28
Anonymous
No

When defining a class that makes use of the __getattr__ method in one module and then importing an instance of that class in another module, the code analysis erroneously reports an 'undefined variable from import' error.

Consider the following example:

---- file config.py ----------
class Config(object):
def __init__(self):
pass

def __getattr__(self, key):
pass

global_config = Config(None)
-------------------------------

---- file example.py ----------
from config import global_config

print global_config.test
print global_config.test.value
-------------------------------

In example.py, line 4 'value' is marked as an 'undefined variable from import: value'.

The Code analysis obvoiusly looks at the class Config and notes __getattr__, because if you remove __getattr__:

---- file config.py ----------
class Config(object):
def __init__(self):
pass

global_config = Config(None)
-------------------------------

you get two errors in config.py, one in line3, and one in line 4, both 'undefined variable from import: test'.

As the code analysis obviously decides that it cannot determine whether or not a given member exists when there is a __getattr__ method, it is my opinion that it should not produce an error because it does not know a member of that unknown member.

Discussion

  • Fabio Zadrozny

    Fabio Zadrozny - 2007-03-25
    • status: open --> closed-fixed
     
  • Fabio Zadrozny

    Fabio Zadrozny - 2007-03-25

    Logged In: YES
    user_id=617340
    Originator: NO

    Fixed for 1.3.1

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks