I recently picked up PyCharm and I’m used to a feature from Wing where you can tell the IDE what class a particular identifier (variable, attribute, whatever) will be. For example:
my_object = SomeClass()
assert isinstance(my_object.my_attribute, SomeOtherClass)
At this point, Wing knows exactly what my_object.my_attribute is even if it couldn’t otherwise figure it out from source code analysis.
I’m looking for a similar feature in PyCharm. I know what a particular attribute of an object is, but PyCharm doesn’t, so how can I tell it, so it can give me handy completions?
Related question: I also do see a similar question, How can I tell PyCharm what type a parameter is expected to be?, but it doesn’t cover attributes, just parameters.
Actually PyCharm also understands the ‘assert isinstance’ syntax, but only for unqualified references. I’ve filed an issue to support this for qualified references as well:
http://youtrack.jetbrains.net/issue/PY-5614
In the current version, you can specify the type of my_attribute by going to the declaration of SomeClass and adding a epydoc or sphinx docstring for the attribute.