code-google-com / pymel

Automatically exported from code.google.com/p/pymel
0 stars 0 forks source link

Virtual Classes bugged in 1.0.5 #307

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I can't register any virtual classes - they are rejected because '__apicls__' 
is an attribute present on the new class, which is not a part of the virtual 
class manager's validSpecialAttrs list. I suspect this has to do with a change 
to the metaclasses for PyNodes adding more attributes to all classes.

What Version of Maya are you using?
Maya 2014

On what operating system? (be as specific as possible and include service
packs, 64bit vs 32bit, etc)
Win7 64bit

What Version of PyMEL are you using?
1.0.5

What is the expected output? What do you see instead?
I expect to not find __apicls__ in the __dict__ of classes inheriting from a 
PyNode.

If possible, provide a few lines of code to reproduce the problem. It helps
us if your code will reproduce the problem from a new scene.

Here's an example that demonstrates the presence of more attributes in 2014:
from pymel.core import *
class NewNet( nt.Network ): pass
NewNet.__dict__.keys()

The result in Maya 2011:
# Result: ['__slots__', '__doc__', '__module__', '__readonly__', '__melnode__'] 
# 
The result in Maya 2014:
# Result: ['__module__', 'MAttrClass', 'MdgTimerState', '__apicls__', 
'__melnode__', '__doc__', '__slots__', 'MdgTimerMetric', '__readonly__', 
'MdgTimerType'] #

Does maya.cmds exhibit the same problem?
n/a

Please provide any additional information below.
Not even the examples from the custom class examples 
(https://github.com/LumaPictures/pymel/blob/master/examples/customClasses.py) 
work on Maya 2014

Original issue reported on code.google.com by kyle.mis...@gmail.com on 20 Sep 2013 at 12:45

GoogleCodeExporter commented 9 years ago
This looks to be a duplicate of issue 295, which contains a fix for the problem.

Original comment by dean.edm...@gmail.com on 23 Jan 2014 at 1:33

GoogleCodeExporter commented 9 years ago
While you can simply add __apicls__ to the list of accepted attributes, it 
seemed like a sort of hacky fix to me, since __apicls__ was not present in the 
exceptions in earlier versions of pymel, yet it still worked fine.
I did some digging and found a difference in 
pymel.internal.factories.MetaMayaNodeWrapper.__new__ where the __apicls__ 
attribute is actually added to the nodes:
# 2014
if apicls is not None:
    classdict['__apicls__'] = apicls

# 2011
if apicls is not None:
    if apicls in MetaMayaNodeWrapper.completedClasses:
        pass        
    else:
        MetaMayaNodeWrapper.completedClasses[ apicls ] = classname
        classdict['__apicls__'] = apicls

Essentially, in 2011, the __apicls__ attr was only added to a node if it had 
not already been added to a parent node. This basically meant that abstract 
node types had the __apicls__ attribute, while the concrete subclasses would 
not, and would work as Virtual Classes.
I think this change is actually the source of the issue.

Original comment by kyle.mis...@gmail.com on 24 Jan 2014 at 9:35

GoogleCodeExporter commented 9 years ago
fixed with:
https://github.com/LumaPictures/pymel/commit/a257f00b37ef9796bbca154d4bc7293ac45
b18dc

Original comment by elron...@gmail.com on 24 Jan 2014 at 10:37