Commits

Jason R. Coombs  committed ec3c3db

Add TagRegistered metaclass

  • Participants
  • Parent commits e194797
  • Tags 10.1

Comments (0)

Files changed (2)

 Changes
 -------
 
+10.1
+~~~~
+
+* Added ``meta.TagRegistered``.
+
 10.0.2
 ~~~~~~
 

File jaraco/util/meta.py

 		leaf_classes.add(cls)
 		# remove any base classes
 		leaf_classes -= set(bases)
+
+
+class TagRegistered(type):
+	"""
+	As classes of this metaclass are created, they keep a registry in the
+	base class of all classes by a class attribute, 'tag'.
+	"""
+	def __init__(cls, name, bases, namespace):
+		super(TagRegistered, cls).__init__(name, bases, namespace)
+		if not hasattr(cls, '_registry'):
+			cls._registry = {}
+		attr = getattr(cls, 'tag', None)
+		if attr:
+			cls._registry[attr] = cls