libb.include

include(source, names=())[source]

Include dictionary items as class attributes during class declaration.

Injects dictionary key-value pairs into the calling class namespace, optionally filtering by specific names.

Parameters:
  • source (dict) – Dictionary containing attributes to include.

  • names (tuple) – Optional tuple of specific attribute names to include (includes all if empty).

Return type:

None

Include All Attributes:

>>> d = dict(x=10, y='foo')
>>> class Foo:
...     include(d)
>>> Foo.x
10
>>> Foo.y
'foo'

Include Specific Attributes:

>>> class Boo:
...     include(d, ('y',))
>>> hasattr(Boo, 'x')
False
>>> hasattr(Boo, 'y')
True