-
Notifications
You must be signed in to change notification settings - Fork 19
Pydantic package organization episode 5: "Only mostly dead" #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5cb8189
6c32661
8902c0e
18f1da1
2546b0b
152f3f5
f3f2c98
4a84e90
eaf55c0
0356a59
e35315e
b1d4fd3
03a6d72
0e40c0c
2ccf9af
966174d
cbd680e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import textwrap | ||
| from enum import Enum | ||
| from typing import Annotated, Any, NewType | ||
|
|
||
| from pydantic import BaseModel, Field | ||
|
|
||
| from overture.schema.system.primitive import float64, int32 | ||
| from overture.schema.system.string import WikidataId | ||
|
|
||
| Depth = NewType( | ||
| "Depth", | ||
| Annotated[ | ||
| int32, | ||
| Field( | ||
| ge=0, | ||
| description="Depth below surface level of the feature in meters.", | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| Elevation = NewType( | ||
| "Elevation", | ||
| Annotated[ | ||
| int32, | ||
| Field( | ||
| le=9000, | ||
| description="Elevation above sea level of the feature in meters.", | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
| Height = NewType( | ||
| "Height", | ||
| Annotated[float64, Field(gt=0, description="Height of the feature in meters.")], | ||
| ) | ||
|
|
||
|
|
||
| SourceTags = NewType( | ||
| "SourceTags", | ||
| Annotated[ | ||
| dict[str, Any], | ||
| Field( | ||
| description=textwrap.dedent(""" | ||
| Key/value pairs imported directly from the source data without change. | ||
|
|
||
| This field provides access to raw OSM entity tags for features sourced from | ||
| OpenStreetMap. | ||
| """).strip() | ||
| ), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| class SourcedFromOpenStreetMap(BaseModel): | ||
| """ | ||
| Model derived from an OpenStreetMap entity and containing the entity's OSM tags and wikidata ID. | ||
| """ | ||
|
|
||
| source_tags: SourceTags | None = None | ||
| wikidata: WikidataId | None = None | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be split out? It may be present in the OSM tags already, so
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Almost definitely yes. It just ended up below my subjective refactoring line. |
||
|
|
||
|
|
||
| class SurfaceMaterial(str, Enum): | ||
| """Material that makes up the surface of `Infrastructure` and `Land` features.""" | ||
|
|
||
| ASPHALT = "asphalt" | ||
| COBBLESTONE = "cobblestone" | ||
| COMPACTED = "compacted" | ||
| CONCRETE = "concrete" | ||
| CONCRETE_PLATES = "concrete_plates" | ||
| DIRT = "dirt" | ||
| EARTH = "earth" | ||
| FINE_GRAVEL = "fine_gravel" | ||
| GRASS = "grass" | ||
| GRAVEL = "gravel" | ||
| GROUND = "ground" | ||
| PAVED = "paved" | ||
| PAVING_STONES = "paving_stones" | ||
| PEBBLESTONE = "pebblestone" | ||
| RECREATION_GRASS = "recreation_grass" | ||
| RECREATION_PAVED = "recreation_paved" | ||
| RECREATION_SAND = "recreation_sand" | ||
| RUBBER = "rubber" | ||
| SAND = "sand" | ||
| SETT = "sett" | ||
| TARTAN = "tartan" | ||
| UNPAVED = "unpaved" | ||
| WOOD = "wood" | ||
| WOODCHIPS = "woodchips" | ||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
_common(private) vs.commonand not exported at the top level?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're all exported from
__init__.py. I guess the answer is just that I find the proliferation of multiple import options confusing and sometimes its easier to have files for code organization but just a single flat import namespace for usability...