fgen.data_models.value#
Data model of a value (e.g. parameter, single return value)
Value#
- class Value(definition, unit=None, dynamic_unit=False)[source]#
Bases:
objectData model of a value
This defines the value’s unit, Fortran data type and other metadata. It is the combination of a
UnitlessValueDefinitionand unit information.-
definition:
fgen.data_models.unitless_value.UnitlessValue# Definition of the value’s key information
-
dynamic_unit:
typing.Union[bool,str]# Whether the unit should be inferred dynamically, rather than statically
If this is
True, we will infer the unit using the units of passedpint.Quantity’s. When passing these values to Fortran, the unit will be extracted and passed to Fortran as a string to the attribute whoseis_fortran_units_holderisTrue. Ifdynamic_unitisTrue, when retrieving the values from Fortran, the unit will be requested from Fortran too (from the attribute whoseis_fortran_units_holderisTrue) and added to the return value to make apint.Quantitybefore returning.If this is a string, we assume this tells us where to retrieve the unit information from on the Python side (i.e. the string should be valid Python code).
- property requires_units: bool#
Whether this value requires units or not
- Returns:
Trueif this value requires units,Falseotherwise.
-
unit:
typing.Optional[str]# Unit of the value
The unit must be able to parsed by pint and be present in the
pint.UnitRegistrybeing used by the application (normal rules for pint). Some examples include: “kg”, “1 / month”.A unit is required for all numeric-types (i.e. integer, real, complex) that don’t have
dynamic_unitset. For non-numeric values, no unit is unused.
-
definition:
no_conversion#
- no_conversion(inp)[source]#
Identity function, just returns what it is given i.e. performs no conversion
The use case for this is disabling type conversion with
cattrsandattrs. In order to getcattrsto not convert stuff, you have to tell the converter a) to prefer attrs converters (i.e. useprefer_attrib_converters=Truewhen creating yourcattrsconverter) and b) actual supply a converter to yourattrsattribute. If you don’t actually want to do any conversion, then you need an identity function (otherwise,cattrswill assume you didn’t think about conversion and inject its own conversion). This lets the validator handle type checking etc., rather than having that check happen in a separate spot (without any context about what is being checked etc.).- Parameters:
inp (
typing.TypeVar(T)) – Input- Returns:
typing.TypeVar(T) –inp, unchanged.