Skip to content

Commit d0a2292

Browse files
committed
Removed Python<=3.10 support.
1 parent 6358498 commit d0a2292

File tree

8 files changed

+33
-84
lines changed

8 files changed

+33
-84
lines changed

.github/workflows/python-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
runs-on: ubuntu-latest
5353
strategy:
5454
matrix:
55-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
55+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
5656
pydantic-version: ["1.10.*", "2.*"]
5757

5858
services:

django_pydantic_field/compat/django.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,18 +300,13 @@ def serialize(self):
300300
if sys.version_info >= (3, 14):
301301
GenericAlias = types.GenericAlias
302302
GenericTypes: ty.Tuple[ty.Any, ...] = (GenericAlias, type(ty.List[int]), type(ty.List), ty.Union)
303-
elif sys.version_info >= (3, 9):
303+
else:
304304
GenericAlias = types.GenericAlias
305305
GenericTypes = (
306306
GenericAlias,
307307
type(ty.List[int]),
308308
type(ty.List),
309309
)
310-
else:
311-
# types.GenericAlias is missing, meaning python version < 3.9,
312-
# which has a different inheritance models for typed generics
313-
GenericAlias = type(ty.List[int]) # noqa
314-
GenericTypes = GenericAlias, type(ty.List) # noqa
315310

316311

317312
# BaseContainerSerializer *must be* registered after all specialized container serializers
@@ -331,21 +326,22 @@ def serialize(self):
331326
MigrationWriter.register_serializer(ty._SpecialForm, TypingSerializer) # type: ignore
332327

333328

334-
if sys.version_info >= (3, 10):
335-
UnionType = types.UnionType
329+
UnionType = types.UnionType
330+
336331

337-
class UnionTypeSerializer(BaseSerializer):
338-
value: UnionType
332+
class UnionTypeSerializer(BaseSerializer):
333+
value: UnionType
334+
335+
def serialize(self):
336+
imports = set()
337+
if isinstance(self.value, (type(ty.Union), types.UnionType)): # type: ignore
338+
imports.add("import typing")
339339

340-
def serialize(self):
341-
imports = set()
342-
if isinstance(self.value, (type(ty.Union), types.UnionType)): # type: ignore
343-
imports.add("import typing")
340+
for arg in get_args(self.value):
341+
_, arg_imports = serializer_factory(arg).serialize()
342+
imports.update(arg_imports)
344343

345-
for arg in get_args(self.value):
346-
_, arg_imports = serializer_factory(arg).serialize()
347-
imports.update(arg_imports)
344+
return repr(self.value), imports
348345

349-
return repr(self.value), imports
350346

351-
MigrationWriter.register_serializer(UnionType, UnionTypeSerializer)
347+
MigrationWriter.register_serializer(UnionType, UnionTypeSerializer)

django_pydantic_field/v2/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,5 @@ def get_origin_type(cls: type):
5757
return cls
5858

5959

60-
if sys.version_info >= (3, 9):
61-
62-
def evaluate_forward_ref(ref: ty.ForwardRef, ns: Mapping[str, ty.Any]) -> ty.Any:
63-
return ref._evaluate(dict(ns), {}, recursive_guard=frozenset())
64-
65-
else:
66-
67-
def evaluate_forward_ref(ref: ty.ForwardRef, ns: Mapping[str, ty.Any]) -> ty.Any:
68-
return ref._evaluate(dict(ns), {})
60+
def evaluate_forward_ref(ref: ty.ForwardRef, ns: Mapping[str, ty.Any]) -> ty.Any:
61+
return ref._evaluate(dict(ns), {}, recursive_guard=frozenset())

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ classifiers = [
3535
"Programming Language :: Python",
3636
"Programming Language :: Python :: 3",
3737
"Programming Language :: Python :: 3 :: Only",
38-
"Programming Language :: Python :: 3.8",
39-
"Programming Language :: Python :: 3.9",
4038
"Programming Language :: Python :: 3.10",
4139
"Programming Language :: Python :: 3.11",
4240
"Programming Language :: Python :: 3.12",
@@ -74,8 +72,7 @@ test = [
7472
"syrupy>=3,<5",
7573
]
7674
ci = [
77-
'psycopg[binary]>=3.1,<4; python_version>="3.9"',
78-
'psycopg2-binary>=2.7,<3; python_version<"3.9"',
75+
'psycopg[binary]>=3.1,<4',
7976
"mysqlclient>=2.1",
8077
]
8178

tests/test_fields.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def test_field_serialization(field):
147147
_test_field_serialization(field)
148148

149149

150-
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Built-in type subscription supports only in 3.9+")
151150
@pytest.mark.parametrize(
152151
"field_factory",
153152
[
@@ -161,30 +160,11 @@ def test_field_builtin_annotations_serialization(field_factory):
161160
_test_field_serialization(field_factory())
162161

163162

164-
@pytest.mark.skipif(sys.version_info < (3, 10), reason="Union type syntax supported only in 3.10+")
165163
def test_field_union_type_serialization():
166164
field = fields.PydanticSchemaField(schema=(InnerSchema | None), null=True, default=None)
167165
_test_field_serialization(field)
168166

169167

170-
@pytest.mark.skipif(sys.version_info >= (3, 9), reason="Should test against builtin generic types")
171-
@pytest.mark.parametrize(
172-
"field",
173-
[
174-
fields.PydanticSchemaField(schema=ty.List[InnerSchema], default=list),
175-
fields.PydanticSchemaField(schema=ty.Dict[str, InnerSchema], default=dict),
176-
fields.PydanticSchemaField(schema=ty.Sequence[InnerSchema], default=list),
177-
fields.PydanticSchemaField(schema=ty.Mapping[str, InnerSchema], default=dict),
178-
],
179-
)
180-
def test_field_typing_annotations_serialization(field):
181-
_test_field_serialization(field)
182-
183-
184-
@pytest.mark.skipif(
185-
sys.version_info < (3, 9),
186-
reason="Typing-to-builtin migrations is reasonable only on py >= 3.9",
187-
)
188168
@pytest.mark.parametrize(
189169
"old_field, new_field",
190170
[

tests/test_migration_serializers.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,16 @@
1717
except ImportError:
1818
annotationlib = None
1919

20-
if sys.version_info < (3, 9):
21-
test_types = [
22-
str,
23-
list,
24-
t.List[str],
25-
t.Union[te.Literal["foo"], t.List[str]],
26-
t.List[t.Union[int, bool]],
27-
t.Tuple[t.List[te.Literal[1]], t.Union[str, te.Literal["foo"]]],
28-
t.ForwardRef("str"),
29-
]
30-
else:
31-
test_types = [
32-
str,
33-
list,
34-
list[str],
35-
t.Literal["foo"],
36-
t.Union[t.Literal["foo"], list[str]],
37-
list[t.Union[int, bool]],
38-
tuple[list[t.Literal[1]], t.Union[str, t.Literal["foo"]]],
39-
t.ForwardRef("str"),
40-
]
20+
test_types = [
21+
str,
22+
list,
23+
list[str],
24+
t.Literal["foo"],
25+
t.Union[t.Literal["foo"], list[str]],
26+
list[t.Union[int, bool]],
27+
tuple[list[t.Literal[1]], t.Union[str, t.Literal["foo"]]],
28+
t.ForwardRef("str"),
29+
]
4130

4231

4332
@pytest.mark.parametrize("raw_type", test_types)

tests/v1/test_base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def test_concrete_types(type_, encoded, decoded):
107107
assert decoder.decode(existing_encoded) == decoded
108108

109109

110-
@pytest.mark.skipif(sys.version_info < (3, 9), reason="Should test against builtin generic types")
111110
@pytest.mark.parametrize(
112111
"type_factory, encoded, decoded",
113112
[

tests/v2/test_types.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1-
import sys
21
import pydantic
32
import pytest
43
import typing as ty
54

65
from ..conftest import InnerSchema, SampleDataclass
76

87
types = pytest.importorskip("django_pydantic_field.v2.types")
9-
skip_unsupported_builtin_subscription = pytest.mark.skipif(
10-
sys.version_info < (3, 9),
11-
reason="Built-in type subscription supports only in 3.9+",
12-
)
138

149

1510
# fmt: off
1611
@pytest.mark.parametrize(
1712
"ctor, args, kwargs",
1813
[
19-
pytest.param(types.SchemaAdapter, ["list[int]", None, None, None], {}, marks=skip_unsupported_builtin_subscription),
20-
pytest.param(types.SchemaAdapter, ["list[int]", {"strict": True}, None, None], {}, marks=skip_unsupported_builtin_subscription),
14+
pytest.param(types.SchemaAdapter, ["list[int]", None, None, None], {}),
15+
pytest.param(types.SchemaAdapter, ["list[int]", {"strict": True}, None, None], {}),
2116
(types.SchemaAdapter, [ty.List[int], None, None, None], {}),
2217
(types.SchemaAdapter, [ty.List[int], {"strict": True}, None, None], {}),
2318
(types.SchemaAdapter, [None, None, InnerSchema, "stub_int"], {}),
2419
(types.SchemaAdapter, [None, None, SampleDataclass, "stub_int"], {}),
25-
pytest.param(types.SchemaAdapter.from_type, ["list[int]"], {}, marks=skip_unsupported_builtin_subscription),
26-
pytest.param(types.SchemaAdapter.from_type, ["list[int]", {"strict": True}], {}, marks=skip_unsupported_builtin_subscription),
20+
pytest.param(types.SchemaAdapter.from_type, ["list[int]"], {}),
21+
pytest.param(types.SchemaAdapter.from_type, ["list[int]", {"strict": True}], {}),
2722
(types.SchemaAdapter.from_type, [ty.List[int]], {}),
2823
(types.SchemaAdapter.from_type, [ty.List[int], {"strict": True}], {}),
2924
(types.SchemaAdapter.from_annotation, [InnerSchema, "stub_int"], {}),

0 commit comments

Comments
 (0)