Some way to provide type hints to the pydev analyzer
Brought to you by:
fabioz
In order to make intellisense a little bit more useful,
it would be great to be able to annotate the code in
various ways so as to provide type hints to the pydev
analyzer. For example, there could be a comment or
some other annotation on methods that could indicate
the type that will be returned. That way, intellisense
could work even if the variable is the result of a
method call.
Logged In: YES
user_id=1529456
Originator: NO
Yes, I Agree. That would be a very good thing.
Logged In: NO
I got good results with constructions like:
if False:
my_obj = SuperCoolClass()
Logged In: YES
user_id=617340
Originator: NO
Probably it should at least take into account:
assert isinstance(obj, MyClass)
Logged In: YES
user_id=536423
Originator: NO
the tag @type/@rtype from epydoc seems not work
Logged In: YES
user_id=617340
Originator: NO
This support was added in 1.3.7 (but docstring analysis for @type/@rtype is not there):
The folowing cases are now considered in code-completion to discover the type of a variable:
* Type/Interface checking: (note that 'assert' is required) assert isinstance(obj, Interface) -- default from python
* assert Interface.implementedBy(obj) -- zope
* assert IsImplementation(obj, Interface) -- custom request
* assert IsInterfaceDeclared(obj, Interface) -- custom request
* Factory methods a = adapt(obj, Interface) -- pyprotocols
* a = obj.GetAdapter(Interface) -- custom request
* a = obj.get_adapter(Interface) -- custom request
* a = GetSingleton(Interface) -- custom request
* a = GetImplementation(Interface) -- custom request
Logged In: NO
assert isinstance(obj, Interface) works like a charm for me.
But still it would be great if @type and @rtype could be supported in future versions.