Understanding
Metaclasses
• Computer science student at TU Berlin
• Software Developer at Charité - Universitätsmedizin
Berlin
• Involved in Flask, ...
What is an object?
What is an instance?
What is a class?
What is a metaclass?
How does an instance
attribute of a classes
metaclass affect that class?
How is this different
from a class attribute?
How does a method of a
classes metaclass affect
that class?
How is this different from
a class method defined
with @classmethod?
Is there anything
unique to metaclasses?
def __new__(cls, name, bases, namespace, **kwargs)!
!
def __init__(self, name, bases, namespace, **kwargs)
How is this different
from class decorators?
@classmethod
def __prepare__(cls, name, bases, **kwargs)
def __call__(self, *args, **kwargs)
(Sane) use cases?
• Form libraries
• ORMs
• Anything declarative
Q&A
Upcoming SlideShare
Loading in …5
×

Understanding Metaclasses

296 views
241 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
296
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Understanding Metaclasses

  1. 1. Understanding Metaclasses
  2. 2. • Computer science student at TU Berlin • Software Developer at Charité - Universitätsmedizin Berlin • Involved in Flask, Werkzeug, Babel and many other open source projects
  3. 3. What is an object?
  4. 4. What is an instance?
  5. 5. What is a class?
  6. 6. What is a metaclass?
  7. 7. How does an instance attribute of a classes metaclass affect that class?
  8. 8. How is this different from a class attribute?
  9. 9. How does a method of a classes metaclass affect that class?
  10. 10. How is this different from a class method defined with @classmethod?
  11. 11. Is there anything unique to metaclasses?
  12. 12. def __new__(cls, name, bases, namespace, **kwargs)! ! def __init__(self, name, bases, namespace, **kwargs)
  13. 13. How is this different from class decorators?
  14. 14. @classmethod def __prepare__(cls, name, bases, **kwargs)
  15. 15. def __call__(self, *args, **kwargs)
  16. 16. (Sane) use cases? • Form libraries • ORMs • Anything declarative
  17. 17. Q&A

×