Values#

Base Class#

class valguard.core.TypedValue(value)[source]#

Bases: ABC, Generic

Validate and store a value of a specific Python type.

Subclasses must define _type, indicating the exact type of value accepted. For example, an IntValue subclass would define _type = int.

For type-checked access, use the as_* properties, like as_int and as_bool.

__repr__()[source]#

Return a detailed representation for error messages.

Return type:

str

__str__()[source]#

Return a string representation suitable for writing to a results file.

Return type:

str

property as_bool: bool#
property as_float: float#
property as_int: int#
property as_str: str#
property to_float: float#

Convert value to float if applicable.

property value: T#

Note

While TypedValue is the base class for all constraint-aware value wrappers, a generic alias is available for convenience:

Value = TypedValue[Any]

Use Value for type annotations when the specific constraint is either irrelevant or varies across use cases. For runtime checks, prefer:

isinstance(obj, TypedValue)

Concrete Value Types#

class valguard.core.IntValue(value)[source]#

Integer value.

property as_int: int#
class valguard.core.FloatValue(value)[source]#

Float value. Formatted to two decimal places for display.

property as_float: float#
class valguard.core.BoolValue(value)[source]#

Boolean value.

property as_bool: bool#
class valguard.core._NumericValue(value)[source]#

Base class for numeric values that support conversion to float via to_float.

property to_float: float#

Convert value to float if applicable.

class valguard.core.StrValue(value)[source]#

String value.

property as_str: str#