obj.fishbreath (fake autocomple by pycharm)

Ok, so some other programmer made a typo:
    render(test=obj.mispeled)
prettyPrint();

There is no "mispeled" on this object.  I came along later and edited code far away from the render call, and pycharm helpfully autocompleted the typo:

def PyCharmTest(obj):
    isinstance(obj, Gallery)
    obj.mis<tab>
    ...lots of other code...
    render(test=obj.mispeled)
prettyPrint();
Why was this so?
Should I have expected something different?
Should I have expected the inspection to find the misspelled attribute?
4 comments
Comment actions Permalink
When PyCharm doesn't know the type of an object, it completes attributes which are used on a reference with the same name elsewhere in the codebase. In that case, it's also not quite feasible to detect that the attribute was misspelled, because we don't know where the declaration might have come from.
0
Comment actions Permalink
Here I tried to tell pycharm the type with:
isinstance(obj, Gallery)

Should that not set the type firmly, at least for the rest of the method?
Note it would be helpful if CTRL-Q showed the inferred type pycharm is detecting!
0
Comment actions Permalink
You need to use 'assert isinstance' or 'if isinstance', not just 'isinstance'.
Ctrl-Q does show the infered type when it is known.
0
Comment actions Permalink
Got it.  With the "assert" pycharm no longer thinks fishbreath and mispeled are valid.
0

Please sign in to leave a comment.