Python is a dynamic language, so static code analyzer cannot introspect everything.
In your case it is absolutely normal that PyDev complains that foo.ball
is an "undefined variable", because it ball
was not defined in the foo
module, it is created at run-time. Eclipse doesn't and cannot know this without actually running the program.
Generally it is bad idea to have this kind of magic.
You have this in your code:
globals()[class_name] = scheme_class
So you are dynamically creating a class without verifying if it was already created and then inject it into the globals
.
Then would suggest you instead of injecting it just return it:
def crate_scheme(class_name, *properties_class):
scheme_class = type(class_name, (Scheme,), dict( _properties_classes={c.__name__:c for c in properties_class} )) # Scheme is another class defined in Foo
return scheme_class
Then you would do in another module:
Ball = foo.create_scheme("ball", color, distance) # color and distance are two classes defined in this module
ball = Ball("color"=red, "distance"=0.5) # __init__ function of Scheme takes care of this, code not shown
This should help getting rid of the PyDev complains, but anyway creating classes on the fly should be avoided if possible: explicit is better than implicit (import this
).
Use composition instead of inheritance here.