Skip to content

First call of pm.menu('test', exists=True) results in a ui.Menu(res) call, where res = cmds.menu('test', exists=True) #471

@chelloiaco

Description

@chelloiaco

Related to issue pymel Maya 2024 #467

The first call of pm.menu containing an "exists" arg is inconsistent with Maya's cmds. It executes the creation of a ui.Menu using the result of the cmds query as the name arg.

On a fresh Maya, the following behavior is noted when checking for a non-existent "test" menu :
pymel (first call - unexpected behavior) :

import pymel.core as pm
pm.menu("test", ex=True)
# Result: ui.Menu('AttributeEditor|MainAttributeEditorLayout|formLayout1|AEmenuBarLayout|False') #

pymel (second call - expected behavior) :

pm.menu("another_test", ex=True)
# Result: False #

The issue happens when on windows.py:1856, the if not kwargs.get('query', kwargs.get('q', False)) passes and allows the execution of _factories.maybeConvert(res, uitypes.Menu) where, in this test, res = False. Note here that we lost the original kwarg ex=True on this call, since we're only using res.

This then eventually calls PyUI.__new__ on uitypes.py:407 with the following args:

name=False <class 'bool'>, # NOT the default None
create=False <class 'bool'>, # default
kwargs={} # default

Which, in turn, passes the uitypes.PyUI._isBeingCreated check on uitypes.py:475, since name=False which, as far as Python cares, is True when not name (uitypes.py:482). This eventually culminates into a cmds.menu(False), which sadly is allowed (yes, using a bool) and creates a menu with the name "False", like so:

cmds.menu(False)
# Result: 'AttributeEditor|MainAttributeEditorLayout|formLayout1|AEmenuBarLayout|False' # 

Subsequent calls probably get caught in a try except in the cmds wrappers, since it will try to create the "False" menu again, which then prevents the menu function's cmds call at line windows.py:476 from returning properly and doesn't create additional ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions