This release includes a lot of improvements to the stubs quality, courtesy of @arvidfm
Python command stubs
- Positional arguments of commands now have default values of
...
- query and/or edit flags are now included for commands detected as queryable and/or editable based on the description
- In query mode, any queryable argument takes a bool unless explicitly specified to only take a value in query mode as well, so these flags are now type hinted as X | bool
- The return type of queryable commands is now a union of the original return type as well as all queryable types
- Commands whose synopsys defines multiple return types are expressed as type unions
- Flags marked as multiuse are now type hinted as X | List[X]
- Improved MEL to Python type conversion
- The maya.cmds stub now includes various type aliases to make the function signatures a bit easier to read, e.g. Queryable[str] for str | bool and Range[float] for Tuple[float] | Tuple[float, float]
Python API stubs
- Literals are now only printed to the stub files if they are simple literals that can actually be represented in Python, e.g. numbers, strings and empty lists/dicts, avoiding syntax errors from sequences like <property object at 0x7fc18a818400> in the stubs
- The parser now keeps track of the fully qualified path of symbols imported from other modules, so e.g. MFnBase will be referenced as maya.OpenMaya.MFnBase when used in OpenMayaUI
- The parser now attempt to guess the types of descriptor class members (property and getset_descriptor attributes) by instantiating the class and retrieving the member via the instance
- The parser also tries to guess the type of parameters using the default value imported by inspect.signature
- Members imported from other modules are no longer included
@staticmethod
and@classmethod
decorators are now detected and included in the stubs- Module-level global variables are now included in the stubs
- Add special cases for init and cls so that the former always returns None, and the latter always has a cls argument
Other various changes
- Stubs are now also generated for the top-level
maya
package inmaya.__init__.pyi
__init__.pyi
files are now included in all directories so that type checkers correctly detect them as Python packages- Any use of Callable is now type hinted as Callable[..., Any] to prevent type checkers for complaining about missing type parameters