Index
frequenz.client.common.types ¤
Common types.
Classes¤
frequenz.client.common.types.InvalidCountryCode
dataclass
¤
A country code that fails the invariant of exactly 2 characters.
Wraps a raw wire country code that is set but not exactly 2 characters long.
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.InvalidCountryCodeError ¤
Bases: InvalidAttributeError
Raised when a semantic accessor sees a country code of length other than 2.
A well-formed country code is an ISO 3166-1 Alpha-2 string, so it must be
exactly 2 characters long. The raw string is available as value.
This is also a ValueError for convenience.
Source code in src/frequenz/client/common/types/_location.py
Attributes¤
attr_name
instance-attribute
¤
attr_name: str = attr_name
The name of the attribute that had an invalid value.
instance
instance-attribute
¤
instance: object = instance
The object instance that had an invalid value.
Methods:¤
__init__ ¤
Initialize this error.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The object instance that had the invalid country code.
TYPE:
|
attr_name
|
The name of the attribute that had the invalid country code.
TYPE:
|
value
|
The invalid country code string.
TYPE:
|
message
|
A custom error message. If
TYPE:
|
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.InvalidLatitude
dataclass
¤
A latitude value that fails the invariant of [-90, 90].
Wraps a raw wire latitude that fell outside the well-formed range.
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.InvalidLatitudeError ¤
Bases: InvalidAttributeError
Raised when a semantic accessor sees a latitude outside [-90, 90].
A well-formed latitude lies in the closed interval [-90, 90]. The raw
out-of-range number is available as value.
This is also a ValueError for convenience.
Source code in src/frequenz/client/common/types/_location.py
Attributes¤
attr_name
instance-attribute
¤
attr_name: str = attr_name
The name of the attribute that had an invalid value.
instance
instance-attribute
¤
instance: object = instance
The object instance that had an invalid value.
Methods:¤
__init__ ¤
Initialize this error.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The object instance that had the invalid latitude.
TYPE:
|
attr_name
|
The name of the attribute that had the invalid latitude.
TYPE:
|
value
|
The out-of-range latitude value.
TYPE:
|
message
|
A custom error message. If
TYPE:
|
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.InvalidLongitude
dataclass
¤
A longitude value that fails the invariant of [-180, 180].
Wraps a raw wire longitude that fell outside the well-formed range.
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.InvalidLongitudeError ¤
Bases: InvalidAttributeError
Raised when a semantic accessor sees a longitude outside [-180, 180].
A well-formed longitude lies in the closed interval [-180, 180]. The raw
out-of-range number is available as value.
This is also a ValueError for convenience.
Source code in src/frequenz/client/common/types/_location.py
Attributes¤
attr_name
instance-attribute
¤
attr_name: str = attr_name
The name of the attribute that had an invalid value.
instance
instance-attribute
¤
instance: object = instance
The object instance that had an invalid value.
Methods:¤
__init__ ¤
Initialize this error.
| PARAMETER | DESCRIPTION |
|---|---|
instance
|
The object instance that had the invalid longitude.
TYPE:
|
attr_name
|
The name of the attribute that had the invalid longitude.
TYPE:
|
value
|
The out-of-range longitude value.
TYPE:
|
message
|
A custom error message. If
TYPE:
|
Source code in src/frequenz/client/common/types/_location.py
frequenz.client.common.types.Location
dataclass
¤
A location's information.
Instances carry the raw wire values of a protobuf Location message.
Invalid or absent field values are expressed in the type system:
latitude and longitude may be
InvalidLatitude or
InvalidLongitude;
country_code may be
InvalidCountryCode or None when the field
was unset on the wire. Users can pattern-match on the fields directly,
or call get_latitude(),
get_longitude(),
get_country_code() and
get_country_code_or_none() to obtain a
validated value or a clear
InvalidAttributeError subclass.
Constructing a Location with a plain number or str that violates
its invariant raises ValueError; use the corresponding Invalid*
type to represent an out-of-invariant wire value.
Source code in src/frequenz/client/common/types/_location.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
Attributes¤
country_code
instance-attribute
¤
country_code: str | InvalidCountryCode | None
The country code.
A plain str (exactly 2 characters, ISO 3166-1 Alpha-2) when
well-formed; an InvalidCountryCode wrapper
when the wire delivered a non-empty string of a different length;
None when the field was unset on the wire (an empty string on the
wire is normalized to None by the converter).
Tip
Use Location.get_country_code() to
obtain a validated str or a clear error.
latitude
instance-attribute
¤
latitude: FloatInt | InvalidLatitude
The latitude.
A plain number when well-formed (in [-90, 90]); an
InvalidLatitude wrapper when the wire delivered
an out-of-range value.
Tip
Use Location.get_latitude() to obtain
a validated number or a clear error.
longitude
instance-attribute
¤
longitude: FloatInt | InvalidLongitude
The longitude.
A plain number when well-formed (in [-180, 180]); an
InvalidLongitude wrapper when the wire
delivered an out-of-range value.
Tip
Use Location.get_longitude() to obtain a
validated number or a clear error.
Methods:¤
__post_init__ ¤
Enforce that plain (unwrapped) fields respect their invariants.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
Source code in src/frequenz/client/common/types/_location.py
__str__ ¤
__str__() -> str
Return the short string representation of this instance.
Source code in src/frequenz/client/common/types/_location.py
get_country_code ¤
get_country_code() -> str
Return the country code as a well-formed 2-character str.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The country code, when it is a well-formed |
| RAISES | DESCRIPTION |
|---|---|
MissingFieldError
|
If |
InvalidCountryCodeError
|
If |
Source code in src/frequenz/client/common/types/_location.py
get_country_code_or_none ¤
get_country_code_or_none() -> str | None
Return the country code as a well-formed str, or None if unset.
Same as get_country_code() but returns
None instead of raising MissingFieldError when
country_code is None (the field was not set
on the wire). Invalid country codes still raise
InvalidCountryCodeError.
| RETURNS | DESCRIPTION |
|---|---|
str | None
|
The country code (when well-formed), or |
| RAISES | DESCRIPTION |
|---|---|
InvalidCountryCodeError
|
If |
Source code in src/frequenz/client/common/types/_location.py
get_latitude ¤
get_latitude() -> FloatInt
Return the latitude as a well-formed number in [-90, 90].
| RETURNS | DESCRIPTION |
|---|---|
FloatInt
|
The latitude, when it is a well-formed number. |
| RAISES | DESCRIPTION |
|---|---|
InvalidLatitudeError
|
If |
Source code in src/frequenz/client/common/types/_location.py
get_longitude ¤
get_longitude() -> FloatInt
Return the longitude as a well-formed number in [-180, 180].
| RETURNS | DESCRIPTION |
|---|---|
FloatInt
|
The longitude, when it is a well-formed number. |
| RAISES | DESCRIPTION |
|---|---|
InvalidLongitudeError
|
If |