2021年1月15日星期五

Python meta class - verifying the name of class where instance of other class with meta was initialized

I'm not sure if it is possible. I need to verify (with meta), the name of class which initializes the instance of class enhanced with meta in order to allow (or not) to use its class methods. I have prepared pseudo code to show what I need.

class meta:      __call__(cls, name, base, dict)      if some_class_name != "b":          del dict("some_func")      class a:      def some_func():          code code    class b:      a_instance = a()      a_instance.some_func()  

a.some_func() can be only used when the class name's where it was called is b. Otherwise this method should be deleted from object.

https://stackoverflow.com/questions/65745521/python-meta-class-verifying-the-name-of-class-where-instance-of-other-class-wi January 16, 2021 at 09:05AM

没有评论:

发表评论