Skip to content

Commit

Permalink
Replace conint etc. with Annotated. Remove obsolete TYPE_CHECKING con…
Browse files Browse the repository at this point in the history
…ditionals.
  • Loading branch information
SyntaxColoring committed Dec 12, 2024
1 parent fe5005e commit 6f5cdba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Gripper configurations."""

from typing_extensions import Annotated, Literal
from typing import TYPE_CHECKING, List, Dict, Tuple, Any, NewType
from pydantic import ConfigDict, BaseModel, Field, conlist
from typing import List, Dict, Tuple, Any, NewType
from pydantic import ConfigDict, BaseModel, Field
from enum import Enum


Expand Down Expand Up @@ -42,20 +42,12 @@ def __str__(self) -> str:
GripperSchema = Dict[str, Any]


if TYPE_CHECKING:
_StrictNonNegativeInt = int
_StrictNonNegativeFloat = float
else:
_StrictNonNegativeInt = Annotated[int, Field(strict=True, ge=0)]
_StrictNonNegativeFloat = Annotated[float, Field(strict=True, ge=0.0)]
_StrictNonNegativeInt = Annotated[int, Field(strict=True, ge=0)]
_StrictNonNegativeFloat = Annotated[float, Field(strict=True, ge=0.0)]


PolynomialTerm = Tuple[_StrictNonNegativeInt, float]

if TYPE_CHECKING:
_Polynomial = List[PolynomialTerm]
else:
_Polynomial = conlist(PolynomialTerm, min_length=1)
_Polynomial = Annotated[List[PolynomialTerm], Field(min_length=1)]


class GripperBaseModel(BaseModel):
Expand Down
10 changes: 3 additions & 7 deletions shared-data/python/opentrons_shared_data/labware/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING, Dict, List, Optional, Union
from typing import Dict, List, Optional, Union
from math import sqrt, asin
from numpy import pi, trapz
from functools import cached_property
Expand Down Expand Up @@ -34,12 +34,8 @@
SAFE_STRING_REGEX = "^[a-z0-9._]+$"


if TYPE_CHECKING:
_StrictNonNegativeInt = int
_StrictNonNegativeFloat = float
else:
_StrictNonNegativeInt = Annotated[int, Field(strict=True, ge=0)]
_StrictNonNegativeFloat = Annotated[float, Field(strict=True, ge=0.0)]
_StrictNonNegativeInt = Annotated[int, Field(strict=True, ge=0)]
_StrictNonNegativeFloat = Annotated[float, Field(strict=True, ge=0.0)]


_Number = Union[StrictInt, StrictFloat]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
"""Python shared data models for liquid class definitions."""

from enum import Enum
from typing import TYPE_CHECKING, Literal, Union, Optional, Sequence, Tuple, Any
from typing import Literal, Union, Optional, Sequence, Tuple, Any

from pydantic import (
BaseModel,
field_validator,
ValidationInfo,
Field,
conint,
confloat,
StrictInt,
StrictFloat,
)
from pydantic.json_schema import SkipJsonSchema
from typing_extensions import Annotated


if TYPE_CHECKING:
_StrictNonNegativeInt = int
_StrictNonNegativeFloat = float
else:
_StrictNonNegativeInt = conint(strict=True, ge=0)
_StrictNonNegativeFloat = confloat(strict=True, ge=0.0)
_StrictNonNegativeInt = Annotated[int, Field(strict=True, ge=0)]
_StrictNonNegativeFloat = Annotated[float, Field(strict=True, ge=0.0)]


_Number = Union[StrictInt, StrictFloat]
Expand Down

0 comments on commit 6f5cdba

Please sign in to comment.