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

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -