container module#
Container classes#
This module provides container classes for organizing and composing objects, along with decorators for inline instantiation and inner class handling. Containers effectively provide namespaces for organizing objects, and the contained objects are considered direct members of the object that the container is a member of. This allows the container to organize objects that are only valid in certain contexts.
- class Container[source]#
Bases:
ContainerNamespace-like container object, will be traversed in all introspection. Can have any attribute set.
- class Structurable[source]#
Bases:
StructurableStructurable container object that supports instantiation in class contexts.
- class Composite(transform)[source]#
Bases:
Container,Kinematic[Transform]Create a geometric composition of objects. This allows the construction of, for example, a landpattern with a part being constructed in its own frame of reference, or a complex symbol to be constructed by composing multiple elements into one.
>>> class MyLandpattern(Landpattern): ... pad1 = MyPad().at(-0.5, 0) ... pad2 = MyPad().at(0.5, 0) ... courtyard = Courtyard(rectangle(2, 1)) ... ... def __init__(self): ... plus = plus_symbol(0.5, 0.1) ... self.plus = Silkscreen(plus.at(0, 1)) ... self.composite = Composite(Transform.rotate(45)) ... self.composite.plus = Silkscreen(plus.at(math.sqrt(2)/2, math.sqrt(2)/2))
- Parameters:
transform (T | None)
- inline(cls)[source]#
Decorator to create a single instance of a class, and replace the class with that instance. Useful for one-of classes, such as the main circuit of a design or a component that has a unique symbol or landpattern that is unlikely to be reused.
>>> class MyDesign(Design): ... @inline ... class Main(Circuit): ... component = ImportantComponent()
- inner(cls)[source]#
Decorator to automatically pass on the outer class’ instance to the inner class. The inner class’
__init__method must accept the outer class as the first argument afterselfas this effectively creates an instance method in the outer class, that creates an instance of the inner class.Here’s a truncated example of it being used in the JITX’s standard library USB protocol
>>> @dataclass(frozen=True) ... class USBStandard: ... skew: Toleranced ... impedance: Toleranced ... loss: float = 12.0 ... ... @inner ... class Constraint[T: USB2](SignalConstraint[T]): ... "Construct a :py:class:`SignalConstraint` applicable to USB topologies of this standard." ... ... def __init__( ... self, ... std: USBStandard, ... structure: DifferentialRoutingStructure | None = None, ... ) -> None: ... self.diffpair_constraint: DiffPairConstraint = DiffPairConstraint(skew: std.skew, loss: std.loss, structure: structure)
>>> class USB(USBStandard, Enum): ... v2 = Toleranced(0, 3.75e-12), Toleranced.percent(90, 15) ... v3 = Toleranced(0, 1e-12), Toleranced.percent(90, 15) ... v4 = Toleranced(0, 1e-12), Toleranced(85, 9)
>>> USB.v2.Constraint() <Constraint object>