Skip to content

Commit ea2a4fb

Browse files
committed
Add back Python 3.8 support
1 parent 6ba4cc3 commit ea2a4fb

13 files changed

+29
-34
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
42+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
4343

4444
env:
4545
UV_PYTHON: ${{ matrix.python-version }}

pydantic_extra_types/color.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
import math
1313
import re
1414
from colorsys import hls_to_rgb, rgb_to_hls
15-
from typing import Any, Callable, Literal, Union, cast
15+
from typing import Any, Callable, Literal, Tuple, Union, cast
1616

1717
from pydantic import GetJsonSchemaHandler
1818
from pydantic._internal import _repr
1919
from pydantic.json_schema import JsonSchemaValue
2020
from pydantic_core import CoreSchema, PydanticCustomError, core_schema
2121

22-
ColorTuple = Union[tuple[int, int, int], tuple[int, int, int, float]]
22+
ColorTuple = Union[Tuple[int, int, int], Tuple[int, int, int, float]]
2323
ColorType = Union[ColorTuple, str, 'Color']
24-
HslColorTuple = Union[tuple[float, float, float], tuple[float, float, float, float]]
24+
HslColorTuple = Union[Tuple[float, float, float], Tuple[float, float, float, float]]
2525

2626

2727
class RGBA:
@@ -115,7 +115,7 @@ def as_named(self, *, fallback: bool = False) -> str:
115115
"""
116116
if self._rgba.alpha is not None:
117117
return self.as_hex()
118-
rgb = cast(tuple[int, int, int], self.as_rgb_tuple())
118+
rgb = cast('tuple[int, int, int]', self.as_rgb_tuple())
119119

120120
if rgb in COLORS_BY_VALUE:
121121
return COLORS_BY_VALUE[rgb]

pydantic_extra_types/coordinate.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
[`Coordinate`][pydantic_extra_types.coordinate.Coordinate] data types.
44
"""
55

6+
from __future__ import annotations
7+
68
from dataclasses import dataclass
7-
from typing import Any, ClassVar
9+
from typing import Any, ClassVar, Tuple
810

911
from pydantic import GetCoreSchemaHandler
1012
from pydantic._internal import _repr
@@ -100,7 +102,7 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
100102
core_schema.no_info_wrap_validator_function(cls._parse_str, core_schema.str_schema()),
101103
core_schema.no_info_wrap_validator_function(
102104
cls._parse_tuple,
103-
handler.generate_schema(tuple[float, float]),
105+
handler.generate_schema(Tuple[float, float]),
104106
),
105107
handler(source),
106108
]

pydantic_extra_types/domain.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from __future__ import annotations
66

77
import re
8-
from collections.abc import Mapping
98
from typing import Any
109

1110
from pydantic import GetCoreSchemaHandler
@@ -54,5 +53,5 @@ def __get_pydantic_core_schema__(cls, source_type: Any, handler: GetCoreSchemaHa
5453
@classmethod
5554
def __get_pydantic_json_schema__(
5655
cls, schema: core_schema.CoreSchema, handler: GetCoreSchemaHandler
57-
) -> Mapping[str, Any]:
56+
) -> dict[str, Any]:
5857
return handler(schema)

pydantic_extra_types/pendulum_dt.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
CoreSchema implementation. This allows Pydantic to validate the DateTime object.
33
"""
44

5+
from __future__ import annotations
6+
57
try:
68
from pendulum import Date as _Date
79
from pendulum import DateTime as _DateTime
@@ -63,7 +65,7 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
6365
return core_schema.no_info_wrap_validator_function(cls._validate, core_schema.datetime_schema())
6466

6567
@classmethod
66-
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> 'DateTime':
68+
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> DateTime:
6769
"""Validate the datetime object and return it.
6870
6971
Args:
@@ -128,7 +130,7 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
128130
return core_schema.no_info_wrap_validator_function(cls._validate, core_schema.date_schema())
129131

130132
@classmethod
131-
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> 'Date':
133+
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Date:
132134
"""Validate the date object and return it.
133135
134136
Args:
@@ -187,7 +189,7 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
187189
return core_schema.no_info_wrap_validator_function(cls._validate, core_schema.timedelta_schema())
188190

189191
@classmethod
190-
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> 'Duration':
192+
def _validate(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Duration:
191193
"""Validate the Duration object and return it.
192194
193195
Args:

pydantic_extra_types/phone_numbers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from collections.abc import Sequence
1010
from dataclasses import dataclass
1111
from functools import partial
12-
from typing import Any, ClassVar, Optional
12+
from typing import Any, ClassVar
1313

1414
from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
1515
from pydantic_core import PydanticCustomError, core_schema
@@ -107,9 +107,9 @@ class SomeModel(BaseModel):
107107
us_number: USNumberType
108108
"""
109109

110-
default_region: Optional[str] = None
110+
default_region: str | None = None
111111
number_format: str = 'RFC3966'
112-
supported_regions: Optional[Sequence[str]] = None
112+
supported_regions: Sequence[str] | None = None
113113

114114
def __post_init__(self) -> None:
115115
if self.default_region and self.default_region not in phonenumbers.SUPPORTED_REGIONS:
@@ -131,7 +131,7 @@ def __post_init__(self) -> None:
131131
def _parse(
132132
region: str | None,
133133
number_format: str,
134-
supported_regions: Optional[Sequence[str]],
134+
supported_regions: Sequence[str] | None,
135135
phone_number: Any,
136136
) -> str:
137137
if not phone_number:

pydantic_extra_types/routing_number.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
[`ABARoutingNumber`][pydantic_extra_types.routing_number.ABARoutingNumber] data type.
33
"""
44

5+
from __future__ import annotations
6+
57
from typing import Any, ClassVar
68

79
from pydantic import GetCoreSchemaHandler
@@ -54,7 +56,7 @@ def __get_pydantic_core_schema__(
5456
)
5557

5658
@classmethod
57-
def _validate(cls, __input_value: str, _: core_schema.ValidationInfo) -> 'ABARoutingNumber':
59+
def _validate(cls, __input_value: str, _: core_schema.ValidationInfo) -> ABARoutingNumber:
5860
return cls(__input_value)
5961

6062
@classmethod

pydantic_extra_types/semver.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
"""
55

66
import warnings
7-
from typing import Annotated, Any, Callable
7+
from typing import Any, Callable
88

99
from pydantic import GetJsonSchemaHandler
1010
from pydantic.json_schema import JsonSchemaValue
1111
from pydantic_core import core_schema
1212
from semver import Version
13+
from typing_extensions import Annotated
1314

1415
warnings.warn(
1516
'Use from pydantic_extra_types.semver import SemanticVersion instead. Will be removed in 3.0.0.', DeprecationWarning

pydantic_extra_types/timezone_name.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_timezones() -> set[str]:
5757
class TimeZoneNameSettings(type):
5858
def __new__(cls, name: str, bases: tuple[type, ...], dct: dict[str, Any], **kwargs: Any) -> type[TimeZoneName]:
5959
dct['strict'] = kwargs.pop('strict', True)
60-
return cast(type[TimeZoneName], super().__new__(cls, name, bases, dct))
60+
return cast('type[TimeZoneName]', super().__new__(cls, name, bases, dct))
6161

6262
def __init__(cls, name: str, bases: tuple[type, ...], dct: dict[str, Any], **kwargs: Any) -> None:
6363
super().__init__(name, bases, dct)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ keep-runtime-typing = true
9292

9393
[tool.ruff]
9494
line-length = 120
95-
target-version = "py39"
95+
target-version = 'py38'
9696

9797
[tool.ruff.lint]
9898
extend-select = [

tests/test_json_schema.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import pycountry
44
import pytest
55
from pydantic import BaseModel
6-
7-
try:
8-
from typing import Annotated
9-
except ImportError:
10-
# Python 3.8
11-
from typing import Annotated
6+
from typing_extensions import Annotated
127

138
import pydantic_extra_types
149
from pydantic_extra_types import epoch

tests/test_phone_numbers_validator.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
from typing import Any, Optional, Union
22

3-
try:
4-
from typing import Annotated
5-
except ImportError:
6-
# Python 3.8
7-
from typing import Annotated
8-
9-
103
import phonenumbers
114
import pytest
125
from phonenumbers import PhoneNumber
136
from pydantic import BaseModel, TypeAdapter, ValidationError
7+
from typing_extensions import Annotated
148

159
from pydantic_extra_types.phone_numbers import PhoneNumberValidator
1610

uv.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)