Maya 2024 stub files

I’m preparing to release Maya 2024 stub files for autocompletion and quick doc display. They are .pyi files meant for Pycharm. Since Autodesk stopped including stub files in the Maya releases, there are several stub file collections available. The difference with mine is that they include ALL documentation. Take a look at an example.

pycharmMayaStub_exampleA

I’ve released Maya stub files since 2008. But I stopped when Autodesk started including their own. Recenlty I dusted off my generator code and updated it. I used to use Highend3D to release the files. But that site is not really stable these days. Does anyone have a suggestion of an easy way to release these that will be easy to access?

12 Likes

I’d suggest putting them on GitHub.

4 Likes

+1 for GitHub.

And huge kudos — would be a huge welcome since they are non-existent in newer devkits.

3 Likes

I am considering using GibLab and not GitHub. I like GitLab’s company policies better and am really not interested in being tied into Microsoft.

1 Like

This is very nice, the fact it uses long names and has the full documentation is chef’s kiss. Looking forward to it!

I was doing some testing with the Maya API stub files in preparation of putting a release package together. Then I realized something rather surprising which I’d never really appreciated before.

Take, for example, OpenMaya.MSelectionList()
MSelectionList add()

add() is overloaded.

The stub files I put together resulted in only one definition for add(). So I modified the generator to output all the variations. But Pycharm would only recognize one of them. Python does not support function overloading.

However, in the typing module there is the @overload decorator which should provide what is needed. This seems to be what the Python builtins (ie. max()) use under the hood.

But again, Pycharm doesn’t recognize this. This issue has been submitted for Pycharm to improve already more than 4 years ago.
Pycharm overload ticket
The last comment was just 2 weeks ago. People consider this issue so important that they are ditching Pycharm for other IDEs.

When I look at other stub files that have been released for Maya, I see that no one has actually dealt with this. I’m wondering how big a deal breaker this is?

pyi files aren’t just for PyCharm. Looks like they are described in multiple PEP’s (I found PEP 484 and PEP 561), so they’re meant to be used by the entire python ecosystem. Anybody using other editors could still benefit from the overloads, and I would absolutely love to have them available.

1 Like

I’m curious which IDE you use that supports @overload. Would be good for me to test with.

My whole studio uses VSCode. It seems to be one of the most popular out there and expandable.

I use the Neovim text editor with PyRight and MyPy Language Server plugins, but that’s a whole rabbit hole of basically relearning how to edit code. You probably shouldn’t mess with that JUST for testing. There’s a notoriously steep learning curve. I still think everybody should give it a try through! Once you learn it, it’s like magic!

Ok, stepping off the soapbox :wink:
PyRight is the LS that comes with vscode, so you could definitely test there.
And MyPy is the reference implementation of python static type checking. I was able to easily find a vscode plugin for that.
You may also want to test with Pyre from Facebook, but that seems a bit more involved to set up.

1 Like

Downloaded VS Code (Pylance) and pointed it to the stub files I have generated. It handles the overloaded methods really nicely.

vsCode_mayaOverload

It provides a nice page flipper widget for the different overloads. And once you have it filled in, it will know to only display the overload that is currently used.

One thing I notice right away though, is the docstring text formatting that Pycharm supports is not supported in VS Code - at least, with default settings. That’s why there’s ** for part of the docstring. That’s supposed to be bolded text.

After doing some more testing, looks like it’s best to make different versions for Pycharm and VS Code. They just do not render docstrings the same.

Hi @cgjedi !

Awesome work and may I suggest that you join this project: GitHub - LumaPictures/cg-stubs: Python stubs for VFX and Animation ? Would be great to have all the cg stubs we need under one “mother” project (If you want to keep it to yourself, I can totally understand though :smiley: )

Cheers,
Fabian

1 Like

I don’t actually support using pymel.

specifically formatted for VS Code:
API

Maya commands

specifically formatted for Pycharm:

API

Maya commands

2 Likes

Ah! The project I linked is indeed from Luma pictures but it is not about pymel. :slight_smile: Instead it it is about generating stubs for common python libraries from the VFX industry and makes them available on PYPI . For example pip install types-nuke types-mari gives you type hinting for Nuke and Mari. They are still missing maya.cmds, so I think you are pretty much a perfect fit for that project.
But I saw that you are not keen to go on GitHub, which I understand and respect. I will shut up now! :grimacing:

1 Like

First release!
Check it out.

Maya2024 stub files

9 Likes

Any comments by anyone who has tried these out?

So you don’t just get radio silence: I can say that the vscode style (haven’t tried the others) loads without error for me, and the docstrings show up. But I haven’t been doing maya cmds devopment for the past couple weeks to really put it through its paces.

Though it would be nice if you built stub-only wheels so the type info could be pip-installed. But that’s just mostly me being greedy :wink:

1 Like

Just to say that this is great!
Also python does support overloaded methods in pyi files you just need to mark them with the overload decorator from the typing module:

@typing.overload
def overloaded_fn(arg1: int) ->int:…

@typing.overload
def overloaded_fn(arg1: str) ->str:…

That should prompt your IDE to properly show overloaded argument signatures.

Also worth noting that pymel ships with its own stubs as of 2024.

1 Like