Skip to content

Instantly share code, notes, and snippets.

@zas
Created March 27, 2019 09:33
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 zas/3e461215fe963f6f7e6b33eca67cc124 to your computer and use it in GitHub Desktop.
Save zas/3e461215fe963f6f7e6b33eca67cc124 to your computer and use it in GitHub Desktop.
class P1():
@property
def name(self):
return getattr(self, 'NAME', self.__class__.__name__)
@property
def title(self):
return getattr(self, 'TITLE', self.name)
class P2Meta(type):
@property
def name(cls):
return getattr(cls, 'NAME', cls.__name__)
@property
def title(cls):
return getattr(cls, 'TITLE', cls.name)
class P2(metaclass=P2Meta):
pass
class PP1(P1):
NAME = 'PP1name'
TITLE = 'PP1title'
class PP2(P2):
NAME = 'PP2name'
TITLE = 'PP2title'
class PP1_notitle(P1):
NAME = 'PP1name_notitle'
class PP2_notitle(P2):
NAME = 'PP2name_notitle'
class PPP1_notitle_noname(P1):
pass
class PPP2_notitle_noname(P2):
pass
for p in (PP1, PP2, PP1_notitle, PP2_notitle, PPP1_notitle_noname,
PPP2_notitle_noname):
print("%r p.title=%r" % (p, p.title))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment