I'd like to 'help' pydev by giving it some info about my types - so that it can provide me with auto-complete information, and so that it doesn't mar
The problem is that I often initially assign attributes the 'None' value, and then set their actual value later. This typically comes up with class types. I guess this is the equivelent of assigning a null value to a reference in other languages.
The result seems to be that pydev/pylint thinks the attribute has a type of None (which is true, initially).
Is there some way that I can 'tell' pydev what the correct type is? Ideally it would be better if I could do this in the source code, rather then in a configuration file, since that would be more convenient and because it is useful information for documenting the program.
I'd be interested in this too - I'd be cool, if you could somehow tell pydev to use the @type tag for the pydoc as reference, but I guess that's also messy and not implemented. I wish Guido had made python 3.0 optionally statically typed. Sigh.
Gunnlaugur Thor Briem
You can do that with assertions. E.g.:
assert isinstance(ds, DataSet)
With the cursor there, PyDev will autocomplete on members of the class DataSet.
That is a good idea, but I find that it doesn't work. I guess pydev doesn't parse the 'isinstance' statement?
I hope it will be supported in the future as it is a good solution to the problem. Then I would define a static member like this:
shape1 = None; # will be used as a Shape object later.
isinstance( shape1, Shape ); # returns False here, but ignored.
assert isinstance( shape1, (NoneType, Shape) );
It should support the assert isinstance(), but I guess it's not working with a tuple as a parameter (please enter a bug request for that).
Are you sure?
I'm finding that it doesn't work in either case. For example:
assert isinstance( attr1, Obj1 );
# here an error is reported, even though member1 is a member of Obj1.