Implement horizontal_spatial_domain factory - #51
Conversation
0919b9a to
d290d85
Compare
| obj["Geometry"] = geometry | ||
| if zone_identifier is not None: | ||
| obj["ZoneIdentifier"] = zone_identifier | ||
| return obj |
There was a problem hiding this comment.
Is there a reason to hold off on adding the orbit and track params and adding the oneOf validation? As it stands now this factory function can produce an empty dict which is invalid as far as the jsonschema goes. I would say if you're not going to add orbit then at least I'd make geometry required / raise a ValueError if geometry is not provided. But I think it would be just cleaner to implement the whole thing, it should be an additional like 10 lines of code.
| def horizontal_spatial_domain( | ||
| geometry: Optional[Geometry] = None, | ||
| zone_identifier: Optional[str] = None, | ||
| ) -> HorizontalSpatialDomain: | ||
| obj: HorizontalSpatialDomain = {} | ||
| if geometry is not None: | ||
| obj["Geometry"] = geometry | ||
| if zone_identifier is not None: | ||
| obj["ZoneIdentifier"] = zone_identifier | ||
| return obj |
There was a problem hiding this comment.
I would also keep the params in the order they are defined in the schema and build the resulting dict in that order when possible, and in this case it is! And I'd keep the formatting consistent with the implementations (empty line before the return statement).
All said and done if I was doing this PR I would commit this:
| def horizontal_spatial_domain( | |
| geometry: Optional[Geometry] = None, | |
| zone_identifier: Optional[str] = None, | |
| ) -> HorizontalSpatialDomain: | |
| obj: HorizontalSpatialDomain = {} | |
| if geometry is not None: | |
| obj["Geometry"] = geometry | |
| if zone_identifier is not None: | |
| obj["ZoneIdentifier"] = zone_identifier | |
| return obj | |
| def horizontal_spatial_domain( | |
| zone_identifier: Optional[str] = None, | |
| geometry: Optional[Geometry] = None, | |
| # TODO(reweeden): Implement typing | |
| orbit: Optional[dict[str, Any]] = None, | |
| # TODO(reweeden): Implement typing | |
| track: Optional[dict[str, Any]] = None, | |
| ) -> HorizontalSpatialDomain: | |
| obj: HorizontalSpatialDomain = {} | |
| if zone_identifier is not None: | |
| obj["ZoneIdentifier"] = zone_identifier | |
| if geometry is not None: | |
| obj["Geometry"] = geometry | |
| if orbit is not None: | |
| obj["Orbit"] = orbit | |
| if track is not None: | |
| obj["Track"] = track | |
| if orbit is None and track is None: | |
| raise ValueError( | |
| "one of 'orbit' or 'track' is required", | |
| ) | |
| return obj |
Co-authored-by: Rohan Weeden <reweeden@alaska.edu>
Pull Request Checklist
I have: