Skip to content

Commit

Permalink
Validate default values in PudlMeta and add None to optional args.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaneselvans committed Nov 26, 2023
1 parent 86c411b commit 628f41a
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/pudl/metadata/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class PudlMeta(BaseModel):

model_config = ConfigDict(
extra="forbid",
validate_all=True,
validate_default=True,
validate_assignment=True,
)

Expand All @@ -246,19 +246,19 @@ class FieldConstraints(PudlMeta):

required: StrictBool = False
unique: StrictBool = False
min_length: PositiveInt = None
max_length: PositiveInt = None
minimum: StrictInt | StrictFloat | datetime.date | datetime.datetime = None
maximum: StrictInt | StrictFloat | datetime.date | datetime.datetime = None
pattern: re.Pattern = None
min_length: PositiveInt | None = None
max_length: PositiveInt | None = None
minimum: StrictInt | StrictFloat | datetime.date | datetime.datetime | None = None
maximum: StrictInt | StrictFloat | datetime.date | datetime.datetime | None = None
pattern: re.Pattern | None = None
enum: StrictList(
String
| StrictInt
| StrictFloat
| StrictBool
| datetime.date
| datetime.datetime
) = None
) | None = None

_check_unique = _validator("enum", fn=_check_unique)

Expand Down Expand Up @@ -526,11 +526,11 @@ class Field(PudlMeta):
"datetime",
"year",
]
title: String = None
title: String | None = None
# Alias required to avoid shadowing Python built-in format()
format_: Literal["default"] = pydantic.Field(alias="format", default="default")
description: String = None
unit: String = None
description: String | None = None
unit: String | None = None
constraints: FieldConstraints = FieldConstraints()
harvest: FieldHarvest = FieldHarvest()
encoder: Encoder | None = None
Expand Down Expand Up @@ -738,7 +738,7 @@ class Schema(PudlMeta):

fields: StrictList(Field)
missing_values: list[StrictStr] = [""]
primary_key: StrictList(SnakeCase) = None
primary_key: StrictList(SnakeCase) | None = None
foreign_keys: list[ForeignKey] = []

_check_unique = _validator(
Expand Down Expand Up @@ -811,8 +811,8 @@ class Contributor(PudlMeta):
"""

title: String
path: AnyHttpUrl = None
email: EmailStr = None
path: AnyHttpUrl | None = None
email: EmailStr | None = None
role: Literal[
"author", "contributor", "maintainer", "publisher", "wrangler"
] = "contributor"
Expand All @@ -837,8 +837,8 @@ class Contributor(PudlMeta):
"supervisor",
"work package leader",
] = "project member"
organization: String = None
orcid: String = None
organization: String | None = None
orcid: String | None = None

@staticmethod
def dict_from_id(x: str) -> dict:
Expand Down Expand Up @@ -874,19 +874,19 @@ class DataSource(PudlMeta):
"""

name: SnakeCase
title: String = None
description: String = None
field_namespace: String = None
title: String | None = None
description: String | None = None
field_namespace: String | None = None
keywords: list[str] = []
path: AnyHttpUrl = None
path: AnyHttpUrl | None = None
contributors: list[Contributor] = []
license_raw: License
license_pudl: License
concept_doi: ZenodoDoi = None
concept_doi: ZenodoDoi | None = None
working_partitions: dict[SnakeCase, Any] = {}
source_file_dict: dict[SnakeCase, Any] = {}
# agency: Agency # needs to be defined
email: EmailStr = None
email: EmailStr | None = None

def get_resource_ids(self) -> list[str]:
"""Compile list of resource IDs associated with this data source."""
Expand Down Expand Up @@ -1118,15 +1118,15 @@ class Resource(PudlMeta):
"""

name: SnakeCase
title: String = None
description: String = None
title: String | None = None
description: String | None = None
harvest: ResourceHarvest = ResourceHarvest()
schema: Schema
# Alias required to avoid shadowing Python built-in format()
format_: String = pydantic.Field(alias="format", default=None)
mediatype: String = None
path: String = None
dialect: dict[str, str] = None
format_: String | None = pydantic.Field(alias="format", default=None)
mediatype: String | None = None
path: String | None = None
dialect: dict[str, str] | None = None
profile: String = "tabular-data-resource"
contributors: list[Contributor] = []
licenses: list[License] = []
Expand All @@ -1142,7 +1142,7 @@ class Resource(PudlMeta):
"pudl",
"ppe",
"eia_bulk_elec",
] = None
] | None = None
etl_group: Literal[
"eia860",
"eia861",
Expand All @@ -1162,7 +1162,7 @@ class Resource(PudlMeta):
"state_demand",
"static_pudl",
"service_territories",
] = None
] | None = None
create_database_schema: bool = True

_check_unique = _validator(
Expand Down Expand Up @@ -1689,10 +1689,10 @@ class Package(PudlMeta):
"""

name: String
title: String = None
description: String = None
title: String | None = None
description: String | None = None
keywords: list[String] = []
homepage: AnyHttpUrl = "https://catalyst.coop/pudl"
homepage: AnyHttpUrl = AnyHttpUrl("https://catalyst.coop/pudl")
created: datetime.datetime = datetime.datetime.utcnow()
contributors: list[Contributor] = []
sources: list[DataSource] = []
Expand Down

0 comments on commit 628f41a

Please sign in to comment.