are docstrings for variables a bad idea?
Diez B. Roggisch
deets at nospam.web.de
Fri Apr 21 09:35:45 EDT 2006
jelle wrote:
>
> why is this ambigious at all?
> am i seriously overlooking something?
Yes. A full example is this:
import random
class A:
"""I'm A
"""
pass
class B:
""" I'm B
"""
pass
def factory():
if random.random() >= .5:
return A()
return B()
o = factory()
Now what is the IDE to show at o for the docstring?
The point is: pythons dynamic nature allows for _runtime_ checks of this
only. Now the special-case of classes can be worked around with a static
analyzer to some extent - because ususally, import statements are easy
enough to spot and resolve statically.
But using __import__ even that can be obfuscated. Now I'm not saying that
this should suppress all efforts to have IDEs more supportive. Yet a class
is a declaration, as is a method - can be parsed easily. But e.g. setting
an instance variable by means of setattr(self, name, value) instead of
self.<name> = value is perfectly legal, often wanted and totally opaque to
any IDE trying to give support.
Diez
More information about the Python-list
mailing list