python 2.7 - Is it dangerous to define __contains__ on a metaclass? -
i'm writing custom enummeta class in python 2.7 collect enum keys , values class , augment class additional fields.
class enummeta(type): def __init__(cls, name, bases, props): cls.__all_values__ = [...] # collect interesting properties def __contains__(cls, value): return value in cls.__all_values__ class thefellowshipofthering(object): __metaclass__ = enummeta frodo = 'frodo baggins' sam = 'samwise "sam" gamgee' merry = 'meriadoc "merry" brandybuck' pippin = 'peregrin "pippin" took' gandalf = 'gandalf grey' aragorn = 'aragorn (strider)' legolas = 'legolas' gimli = 'gimli' boromir = 'boromir' print 'gandalf grey' in thefellowshipofthering @ true print 'saruman' in thefellowshipofthering @ false i'm wondering if implementing container-specific functions, such __contains__, on metaclass dangerous thing do, , if so, why?
Comments
Post a Comment