345 """Register a subclass of this ABC with the given key (a string, 346 number, type, or other hashable). 348 Register may only be called once for a given key or a given subclass. 351 raise ValueError(
"None may not be used as a key.")
352 if subclass
in cls._registry.values():
354 "This subclass has already registered with another key; " 355 "use alias() instead." 357 if cls._registry.setdefault(key, subclass) != subclass:
358 if len(cls.TEMPLATE_PARAMS) == 1:
359 d = {cls.TEMPLATE_PARAMS[0]: key}
361 d = {k: v
for k, v
in zip(cls.TEMPLATE_PARAMS, key)}
363 "Another subclass is already registered with {}".
format(d)
367 if cls.TEMPLATE_DEFAULTS:
368 defaults = (cls.TEMPLATE_DEFAULTS[0]
if 369 len(cls.TEMPLATE_DEFAULTS) == 1
else 370 cls.TEMPLATE_DEFAULTS)
372 conflictStr = (
"Base class has attribute {}" 373 " which is a {} method of {}." 374 " Cannot link method to base class.")
383 for name
in subclass.__dict__:
384 if name
in (
"__new__",
"__init_subclass__"):
386 obj = subclass.__dict__[name]
388 isBuiltin = isinstance(obj, types.BuiltinFunctionType)
389 isStatic = isinstance(obj, staticmethod)
390 if isBuiltin
or isStatic:
391 if hasattr(cls, name):
392 raise AttributeError(
393 conflictStr.format(name,
"static", subclass))
394 setattr(cls, name, obj)
396 elif isinstance(obj, classmethod):
397 if hasattr(cls, name):
398 raise AttributeError(
399 conflictStr.format(name,
"class", subclass))
400 setattr(cls, name, getattr(subclass, name))
402 def setattrSafe(name, value):
404 currentValue = getattr(subclass, name)
405 if currentValue != value:
406 msg = (
"subclass already has a '{}' attribute with " 409 msg.format(name, currentValue, value)
411 except AttributeError:
412 setattr(subclass, name, value)
414 if len(cls.TEMPLATE_PARAMS) == 1:
415 setattrSafe(cls.TEMPLATE_PARAMS[0], key)
416 elif len(cls.TEMPLATE_PARAMS) == len(key):
417 for p, k
in zip(cls.TEMPLATE_PARAMS, key):
421 "key must have {} elements (one for each of {})".
format(
422 len(cls.TEMPLATE_PARAMS), cls.TEMPLATE_PARAMS
426 for name, attr
in cls._inherited.
items():
427 setattr(subclass, name, attr)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
std::vector< SchemaItem< Flag > > * items