Skip to content

hyera.types

Public Puppet type objects: Integer[1, 2], Optional[String], ...

One class per Puppet type a user writes in a type expression. Three things one of these classes can mean, by how it is used:

  • Bare (Integer): the unparameterized type.
  • Subscripted (Integer[1, 10], Optional[String]): a parameterized type, built exactly as :func:hyera._types.parser.parse_type would parse the equivalent Puppet text.
  • Called (Integer("42")): Puppet's new(), returning a plain value (int for Integer, str for String, ...), never an instance of the class itself.

Every one of the first two forms answers isinstance the Puppet way: isinstance(5, Integer) and isinstance(5, Integer[1, 10]) both work, without Integer subclassing int (bool/NoneType cannot be subclassed, and a builtin subclass breaks yaml.safe_dump). Every class here is not re-exported from top-level hyera (hyera.types.Integer, not hyera.Integer) -- the one exception is :class:hyera.Sensitive, already public there as the value wrapper; it gains Sensitive[T] here (a type) alongside its existing Sensitive(x) (a value), both the same object as hyera.Sensitive.

Internal code must never rely on isinstance(type_obj, <one of these classes>) to dispatch on a type object's kind -- these classes are never the type of a type object (the private classes in :mod:hyera._types.types are); that question means "is this value of that Puppet type" here. Internal dispatch still uses the private classes directly, unaffected by anything in this module.

Sensitive = _priv.Sensitive module-attribute

TypeLike = _ty.Union[str, type, _priv.Any] module-attribute

Any

Puppet's Any: every value is an instance. Not parameterizable.

Array

Puppet's Array, optionally of an element type (Array[Integer]) and/or size-bound (Array[Integer, 1, 10], Array[1, 10] with no element type).

Boolean

Puppet's Boolean, optionally fixed to one value (Boolean[True]).

Collection

Puppet's Collection: an Array or Hash, optionally size-bound (Collection[1, 10]).

Data

Puppet's Data alias: Variant[ScalarData, Undef, Hash[String, Data], Array[Data]]. Not parameterizable.

Enum

Puppet's Enum: a str instance equal to one of the given values (Enum["a", "b"]).

Float

Puppet's Float, optionally range-bound (Float[0.0, 1.0]), exactly as :class:Integer.

Hash

Puppet's Hash, optionally of key/value types (Hash[String, Integer]) and/or size-bound (Hash[String, Integer, 1, 10]).

Integer

Puppet's Integer, optionally range-bound (Integer[1, 10], Integer[1] for "at least 1"); None as either bound is Puppet's default (unbounded).

NotUndef

Puppet's NotUndef: any value but None, optionally of a contained type (NotUndef[Integer]) or matching a literal string.

Numeric

Puppet's Numeric: an int or a float, never a bool. Not parameterizable.

Optional

Puppet's Optional: None, or an instance of the contained type (Optional[Integer]) or matching a literal string.

Pattern

Puppet's Pattern: a str instance matching one of one or more regular expressions (Pattern["^a", "^b"], each a str regex source or a compiled re.Pattern).

Regexp

Puppet's Regexp, optionally matching one exact pattern source (Regexp["^a.*"] or Regexp[re.compile("^a.*")]).

RichData

Puppet's RichData alias: :class:Data plus Sensitive, Binary, SemVerRange, Type, TypeSet, URI and Object values. Not parameterizable.

Scalar

Puppet's Scalar: a bool, int, float, str or compiled regexp. Not parameterizable.

ScalarData

Puppet's ScalarData: a bool/int/float/str, or an Array/Hash containing only those (and, for a Hash, str keys). Not parameterizable.

String

Puppet's String, optionally length-bound (String[1, 10], String[1] for "at least 1 character").

Struct

Puppet's Struct: a dict matching a fixed key/value-type shape, given as one mapping argument (Struct[{"a": Integer}]); a key may be a plain str (required) or Optional["k"]/NotUndef["k"] (built from this same module, as a dict key) for an optional one.

Tuple

Puppet's Tuple: a fixed-shape array of per-position types (Tuple[Integer, String]), optionally size-bound as its own trailing int argument/pair (Tuple[Integer, 1, 3] repeats the last type).

Undef

Puppet's Undef: only None. Not parameterizable.

Variant

Puppet's Variant: a value matching any of the given types (Variant[Integer, String]).