Skip to content

Instantly share code, notes, and snippets.

@adamchainz
Created July 8, 2021 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamchainz/78f3a73076d720fc4acc15d32ade980f to your computer and use it in GitHub Desktop.
Save adamchainz/78f3a73076d720fc4acc15d32ade980f to your computer and use it in GitHub Desktop.
metaclass repr puzzle
$ cat base.py
class MyMeta(type):
def __new__(mcs, name, bases, attrs):
return super().__new__(mcs, name, bases, attrs)
class MyBase(metaclass=MyMeta):
pass
$ python -c 'from base import MyBase
class A(MyBase): pass
B = type("B", (MyBase,), {})
print(repr(A))
print(repr(B))'
<class '__main__.A'>
<class 'base.B'>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment