check
unknown
plain_text
2 months ago
1.1 kB
7
Indexable
import sys import functools import sys class AnnouncerMeta(type): """ Print method name when called. FIXME Something is wrong here, please fix it. """ def __new__(cls, class_name, bases, namespace): for name, func in list(namespace.items()): if callable(func): @functools.wraps(func) def call_wrapper(*args, **kwargs): try: return func(*args, **kwargs) finally: print(f"Called {name}") namespace[name] = call_wrapper return type.__new__(cls, class_name, bases, namespace) # Leave code below as is; focus on fixing the metaclass class ExampleClass(metaclass=AnnouncerMeta): """ Just example of class using AnnouncerMeta class. """ def foo(self, n): return f"foo{n}" def bar(self, n): return f"bar{n}" test_name = sys.stdin.readline().strip() if test_name == "sample_test": instance = ExampleClass() print(instance.foo(1) + instance.bar(2))
Editor is loading...
Leave a Comment