FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve `Location` validation and error handling by llucax · Pull Request #248 · frequenz-floss/frequenz-client-common-python · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (15) All 1 file type selected
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
21 changes: 21 additions & 0 deletions src/frequenz/client/common/microgrid/_microgrid.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ def get_delivery_area_or_none(self) -> DeliveryArea | None:
case unknown:
assert_never(unknown)

def get_location(self) -> Location:
"""Return the location as a [`Location`][....types.Location].

This is the higher-level accessor for the [`location`][..location]
attribute: it resolves the field to a
[`Location`][....types.Location] or raises a clear, catchable error.

The returned instance may still carry raw wire values that fail the
[`Location`][....types.Location] field invariants; use its own
`get_*()` accessors to obtain validated coordinates and country code.

Returns:
The location, when it is set.

Raises:
MissingFieldError: If the location is not set (`None`).
"""
if self.location is None:
raise MissingFieldError(self, "location")
return self.location

def __str__(self) -> str:
"""Return the ID of this microgrid as a string."""
name = f":{self.name}" if self.name else ""
Expand Down
16 changes: 15 additions & 1 deletion src/frequenz/client/common/types/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@
"""Common types."""

from ._lifetime import Lifetime
from ._location import Location
from ._location import (
InvalidCountryCode,
InvalidCountryCodeError,
InvalidLatitude,
InvalidLatitudeError,
InvalidLongitude,
InvalidLongitudeError,
Location,
)

__all__ = [
"InvalidCountryCode",
"InvalidCountryCodeError",
"InvalidLatitude",
"InvalidLatitudeError",
"InvalidLongitude",
"InvalidLongitudeError",
"Lifetime",
"Location",
]
Loading
Loading

Back | FazBrowse Home | New Git URL