markj3d / Red9_StudioPack_Python3

Red9 StudioPack for Maya : converted for Python3
BSD 3-Clause "New" or "Revised" License
19 stars 4 forks source link

No longer able to add MetaClass to set (unhashable type) #1

Open pfleer opened 3 years ago

pfleer commented 3 years ago

Hi Mark,

Thanks for starting the Python 3 repo! Unfortunately I've noticed you can no longer add MetaClasses to a set anymore; this now raises a TypeError because MetaClass is an unhashable type.

My test code (working in Python 2, not in 3)

from Red9 import setup
setup.start()
import Red9.core.Red9_Meta as r9m
from maya import cmds

group = cmds.group(name='test', empty=True)
testNode = r9m.MetaClass(node=group, name='TestMetaNode')

s = set()
s.add(testNode)

Let me know if I can help with more info.

markj3d commented 3 years ago

Interesting, I'll add it to the debug list and do a bit of testing next time I'm in the codebase for Python3, still running the Python2 as trunk as all of our clients are in that build.

thanks

Mark

On Wed, 5 May 2021 at 03:06, pfleer @.***> wrote:

Hi Mark,

Thanks for starting the Python 3 repo! Unfortunately I've noticed you can no longer add MetaClasses to a set anymore; this now raises a TypeError because MetaClass is an unhashable type.

My test code (working in Python 2, not in 3)

from Red9 import setup setup.start() import Red9.core.Red9_Meta as r9m from maya import cmds

group = cmds.group(name='test', empty=True) testNode = r9m.MetaClass(node=group, name='TestMetaNode')

s = set() s.add(testNode)

Let me know if I can help with more info.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/markj3d/Red9_StudioPack_Python3/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANGPPR7JGOXCSL6WMEZZ7TTMCR2BANCNFSM44DZBMRQ .

--

Mark Jackson CEO / Technical Director red9consultancy.com

pfleer commented 3 years ago

It seems that because you define an __eq__ method that the class now also needs an equivalent __hash__ method in Python 3. https://docs.python.org/3.1/reference/datamodel.html#object.__hash__

pfleer commented 3 years ago

I don't want to pretend like I know how to fix this...but this seems to work on my subclasses

def __hash__(self):
    return hash(self.getUUID())