How to make IDE identify Pymel return type?

I’m currently learning pymel to gain the advantage of oop.
But it seems pycharm or vs code autocomplete feature cannot correctly recognize the returned type of ls() function.
For example,if I input following snippet:

meshes = ls(selection = True) 
for mesh in meshes:
    mesh.methodname()

The IDE can only identify ‘mesh’ variable as PyNode ,rather than the exact child class,such as Transform or Mesh .And thus,the IDE cannot provide the child classes’ methods autocompletion,which is very painful.
I am wondering if there is any solution for this issue?
Much appreciated.

Have you added the completion folder from the devkit to your interpreter in pycharm?
also there are a few cases where types can not be inferred since things like ls can return multiple different types. Since python2 does not support type annotations if you want to add the hints as comments like this # type: TypeName after declaring a new var.

1 Like

Thank you for the reply.
I did add the py autocomplete folder,which is in the deck it, for both pycharm and vs code,and it did work, technically speaking.The IDE can provide PyNode method as expected,and can also provide child classes methods if I create a specific instance.
But it’s truly disappointing that the IDE cannot identify the element’s type in a list.
Seems the only solution is to add type hints for element variables in the meshes.
Again,thanks for your support, passerby. :kissing_heart: Really appreciated

1 Like

I’ve been typing #type: Ignore so much I wrote a custom function in my editor to toggle it for each line lol. I should have tried hinting!

I don’t really see how you expected this to work in the way that you’ve described.

pmc.ls is able to return many different types of things (all of which are sub class PyNode), especially if you’re just querying the current selection. As your selection could be literally any type of node and is something only determinable at runtime, how is the IDE going to be able to type hint correctly in this case?

1 Like

Yeah,I get your point.
The element in that list is only determinable at runtime.
I still can get methods autocompletion by manually adding type annotation.
But still it’s good to have some type hints for programming newbies like me.
Do you have some effecient ways to remember all the methods in such an amount of types?