use of __new__ to permit "dynamic" completion within (any?) IDE ?
Jean-Michel Pichavant
jeanmichel at sequans.com
Wed Dec 8 10:55:37 EST 2010
>> quoting eclipse page:
>>
>> "Pydev [...] uses advanced type inference techniques to provide features
>> such code completion and code analysis"
>>
>> I don't know exactly what's hidden behind this marketing stuff. Did you
>> try to document your method with a markup language supported by Eclipse
>> (if there is any)?
>>
>
> pydev completion apparently is restricted (as far as i see) to some
> very specific cases (basically it works when you import a module at
> top of another one and that you instantiate objects from the imported
> module within the init methods of the classes of the module which is
> importing the other one (but so "circular" references created on some
> objects from the first module (the one imported) in the second one
> won't have the completion working for them (that's what I see)).
>
To understand what is possible and what is not, you simply need to think
like a completion feature.
case 1:
self.object = MyClass()
self.object is a MyClass instance, easy stuff I need to parse MyClass
and get the list of attributes/method
case 2:
self.object = object1
There may be simply no way to know the type/class of object1, object1
could be even of an inconsistent type, sometimes None, int, MyClass, who
knows ?
Your trick worked because you found a way to write self.object =
MyClass(object1) and getting barely the same effect than self.object =
object1.
I'm still thinking that's it's a bad idea. In any case your IDE can
still be fooled by the dynamic of python (like pylint is)
How to write python code then ? Well I guess most people either knows
all the attributes by heart, have the documentation, or a split screen
to the class definition, possibly folded using advanced text editor
feature. You need to forget about code completion with any dynamic
language. I also sometimes use an ipython shell to instanciate objects
and inspect their attributes.
JM
More information about the Python-list
mailing list