metaclasses Flashcards

1
Q

define class with metaclass

A
class Widget(object, metaclass=type):
	pass
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

class definition in detail

A
namespace = metaclass.\_\_prepare\_\_(name, bases, **kwargs)
Wiget = metaclass.\_\_new\_\_(metaclass, name, bases, namespace, **kwargs)
metaclass.\_\_init\_\_(Widget, name, bases, namespace, **kwargs)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when __prepare__ override ?

A

cusomize the type or initial value of the namespace mapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when __new__ override?

A

allocate and optionally configure new class object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

where **kwargs comes from?

A
from class definition
class MyClass(metaclass=MyMetaclass, kwarg1 ="asdf):
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

metamethod difference from @classmethod

A

metamethod is not visible from instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

a = MyClass() What method invoked?

A

MyClass.__class__.__call__()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly