Skip to content

Commit 647ee49

Browse files
committed
Modernize examples
1 parent bd7fc1a commit 647ee49

10 files changed

Lines changed: 30 additions & 27 deletions

examples/forward_reference.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from __future__ import annotations
2-
31
from dataclasses import dataclass
2+
43
from serde import serde
54
from serde.json import from_json, to_json
65

examples/generics.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
from typing import Generic, TypeVar
2-
31
from serde import from_dict, serde, to_dict
42

5-
T = TypeVar("T")
6-
73

84
@serde
95
class Bar:
106
n: int
117

128

139
@serde
14-
class Foo(Generic[T]):
10+
class Foo[T]:
1511
inner: T
1612

1713

1814
@serde
19-
class Baz(Generic[T]):
15+
class Baz[T]:
2016
foo: Foo[T]
2117

2218

examples/generics_nested.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import Generic, TypeVar
2-
31
from serde import from_dict, serde, to_dict
42

53

@@ -15,17 +13,15 @@ class A(EventData):
1513

1614
# Additional subclasses of EventData exist
1715

18-
Data = TypeVar("Data", bound=EventData)
19-
2016

2117
@serde
22-
class Payload(Generic[Data]):
18+
class Payload[Data: EventData]:
2319
id: int
2420
data: Data
2521

2622

2723
@serde
28-
class Event(Generic[Data]):
24+
class Event[Data: EventData]:
2925
name: str
3026
payload: Payload[Data]
3127

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
from typing import Generic, TypeVar
2+
13
from serde import from_dict, serde, to_dict
24

5+
T = TypeVar("T")
6+
37

48
@serde
59
class Bar:
610
n: int
711

812

913
@serde
10-
class Foo[T]:
14+
class Foo(Generic[T]):
1115
inner: T
1216

1317

1418
@serde
15-
class Baz[T]:
19+
class Baz(Generic[T]):
1620
foo: Foo[T]
1721

1822

examples/lazy_type_evaluation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import annotations
2-
31
from serde import serde
42
from serde.json import from_json, to_json
53

examples/recursive.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
from dataclasses import dataclass
32

43
from serde import from_dict, serde, to_dict

examples/recursive_list.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from __future__ import annotations
21
from dataclasses import dataclass
32

43
from serde import serde

examples/recursive_union.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from __future__ import annotations
2-
from serde import serde, to_dict, InternalTagging, from_dict
31
from dataclasses import dataclass
42

3+
from serde import InternalTagging, from_dict, serde, to_dict
4+
55

66
@serde(tagging=InternalTagging("type"))
77
@dataclass

examples/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import typing
33

44

5-
if sys.version_info[:3] < (3, 12, 0):
6-
print("examples require at least Python 3.12")
5+
if sys.version_info[:3] < (3, 14, 0):
6+
print("examples require at least Python 3.14")
77
sys.exit(1)
88

99

pyproject.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ include = [
121121
exclude = [
122122
"serde/numpy.py",
123123
"serde/__init__.py",
124-
"examples/type_numpy_jaxtyping.py"
124+
"examples/type_numpy_jaxtyping.py",
125+
"examples/forward_reference.py",
126+
"examples/recursive.py",
127+
"examples/recursive_list.py",
128+
"examples/recursive_union.py",
129+
"examples/lazy_type_evaluation.py",
125130
]
126131
pythonVersion = "3.12"
127132
reportMissingImports = false
@@ -134,7 +139,8 @@ ignore_missing_imports = true
134139
exclude = [
135140
"serde/numpy.py",
136141
"examples/alias.py",
137-
"examples/generics_pep695.py",
142+
"examples/generics.py",
143+
"examples/generics_nested.py",
138144
"examples/custom_class_serializer.py",
139145
"examples/global_custom_class_serializer.py",
140146
"tests/.*",
@@ -150,9 +156,15 @@ ignore_errors = true
150156
[tool.ruff]
151157
line-length = 100
152158
extend-exclude = [
153-
"examples/generics_pep695.py",
159+
"examples/generics.py",
160+
"examples/generics_nested.py",
154161
"examples/type_alias_pep695.py",
155162
"examples/type_statement.py",
163+
"examples/forward_reference.py",
164+
"examples/recursive.py",
165+
"examples/recursive_list.py",
166+
"examples/recursive_union.py",
167+
"examples/lazy_type_evaluation.py",
156168
]
157169

158170
[tool.ruff.lint]

0 commit comments

Comments
 (0)