Skip to content

Commit

Permalink
Use validator function argument typing based on Pydantic documentation
Browse files Browse the repository at this point in the history
The first argument in the validators was changed to type Any for all
relevant functions. This is the recommended pattern from the Pydantic
documentation.
  • Loading branch information
JeremyMcCormick committed Jan 29, 2024
1 parent c982ea8 commit bd48618
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/felis/datamodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def check_unique_table_names(cls: Any, tables: list[Table]) -> list[Table]:
return tables

@model_validator(mode="after")
def create_id_map(self) -> "Schema":
def create_id_map(self: "Schema") -> "Schema":
"""Create a map of IDs to objects."""
visitor: SchemaVisitor = SchemaVisitor()
visitor.visit_schema(self)
Expand Down
9 changes: 4 additions & 5 deletions python/felis/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import logging
from typing import Type
from typing import Any, Type

from pydantic import Field, conlist, model_validator

Expand All @@ -46,8 +46,7 @@ class RspTable(Table):
"""

description: str = Field(..., min_length=1)
"""Redefine description so that it is required and non-empty.
"""
"""Redefine description so that it is required and non-empty."""

tap_table_index: int = Field(..., alias="tap:table_index")
"""Redefine the TAP_SCHEMA table index so that it is required."""
Expand All @@ -57,7 +56,7 @@ class RspTable(Table):

@model_validator(mode="after") # type: ignore
@classmethod
def check_tap_principal(cls, tbl: "RspTable") -> "RspTable":
def check_tap_principal(cls: Any, tbl: "RspTable") -> "RspTable":
"""Check that at least one column is flagged as the TAP principal."""
for col in tbl.columns:
if col.tap_principal == 1:
Expand All @@ -80,7 +79,7 @@ class RspSchema(Schema):

@model_validator(mode="after") # type: ignore
@classmethod
def check_tap_table_indexes(cls, sch: "RspSchema") -> "RspSchema":
def check_tap_table_indexes(cls: Any, sch: "RspSchema") -> "RspSchema":
"""Check that the TAP table indexes are unique."""
table_indicies = set()
for table in sch.tables:
Expand Down

0 comments on commit bd48618

Please sign in to comment.