units
adh.geom.units
¤
Define Pydantic ping.Quantity.
Derived works from pydantic-pint with modifications:
- Support validation of a list
pydantic-pint license:
MIT License
Copyright (c) 2024-2025 Tyler Hughes
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the
Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes:
-
PintAnno–Pydantic Pint Annotation.
Functions:
-
get_registry–Get the shared Pint Unit Registry.
PintAnno
¤
PintAnno(_arg: PintQty, /, *, ureg: Optional[UnitRegistry] = None)
Pydantic Pint Annotation.
Parameters:
-
_arg(PintQ) –Either the units or dimensions to check the Pydantic field. For example,
"sec","[length]", or{"[length]": 1, "[time]": -2} -
ureg(Optional[UnitRegistry], default:None) –A custom Pint unit registry
Methods:
-
__get_pydantic_core_schema__–Gets the Pydantic core schema.
-
serialize–Serialise a Pydantic Pint Quantity.
-
validate–Validate a Pydantic Pint Quantity.
Source code in src/adh/geom/units.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
__get_pydantic_core_schema__
¤
__get_pydantic_core_schema__(source_type: Any, handler: GetCoreSchemaHandler) -> CoreSchema
Gets the Pydantic core schema.
Parameters:
-
source_type(Any) –The source type.
-
handler(GetCoreSchemaHandler) –The
GetCoreSchemaHandlerinstance.
Returns:
-
CoreSchema–The Pydantic core schema.
Source code in src/adh/geom/units.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
serialize
¤
serialize(v: PlainQuantity, info: SerializationInfo | None = None) -> dict
Serialise a Pydantic Pint Quantity.
Source code in src/adh/geom/units.py
129 130 131 132 133 134 135 136 137 138 | |
validate
¤
validate(v: dict | str | Number | PlainQuantity, info: ValidationInfo | None = None) -> PlainQuantity
Validate a Pydantic Pint Quantity.
Source code in src/adh/geom/units.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
get_registry
¤
get_registry() -> UnitRegistry
Get the shared Pint Unit Registry.
Source code in src/adh/geom/units.py
55 56 57 | |