Skip to content

Commit 302b04b

Browse files
authored
build: drop pydantic 1 (#263)
* drop pydantic 1 * relax pydantic pin * remove more
1 parent 8e94394 commit 302b04b

File tree

12 files changed

+24
-83
lines changed

12 files changed

+24
-83
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ repos:
2828
- id: mypy
2929
files: "^src/"
3030
additional_dependencies:
31-
- pydantic >2
32-
- pydantic-compat
31+
- pydantic >2.8
3332
- in-n-out
3433

3534
- repo: local

pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ classifiers = [
3838
dynamic = ["version"]
3939
dependencies = [
4040
"psygnal>=0.10",
41-
"pydantic>=1.10.18",
42-
"pydantic-compat>=0.1.1",
41+
"pydantic>=2.8",
4342
"in-n-out>=0.1.5",
4443
"typing_extensions>=4.12",
4544
]
@@ -53,7 +52,7 @@ qt = ["qtpy>=2.4.0", "superqt[iconify]>=0.7.2"]
5352
pyqt5 = [
5453
"app-model[qt]",
5554
"PyQt5>=5.15.10",
56-
"pyqt5-qt5<=5.15.2; sys_platform == 'win32'",
55+
"pyqt5-qt5==5.15.2; sys_platform == 'win32'",
5756
"pyqt5-qt5>=5.15.4; sys_platform != 'win32'",
5857
]
5958
pyqt6 = ["app-model[qt]", "PyQt6>=6.4.0"]
@@ -154,8 +153,6 @@ filterwarnings = [
154153
"error",
155154
"ignore:Enum value:DeprecationWarning:superqt",
156155
"ignore:Failed to disconnect::pytestqt",
157-
"ignore:Failing to pass a value to the 'type_params' parameter::pydantic",
158-
"ignore:`__get_validators__` is deprecated and will be removed",
159156
]
160157

161158
# https://mypy.readthedocs.io/en/stable/config_file.html

src/app_model/expressions/_expressions.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import (
77
TYPE_CHECKING,
88
Any,
9-
Callable,
109
Generic,
1110
SupportsIndex,
1211
TypeVar,
@@ -342,11 +341,6 @@ def __reduce_ex__(self, protocol: SupportsIndex) -> tuple[Any, ...]:
342341
rv[1] = tuple(getattr(self, f) for f in self._fields)
343342
return tuple(rv)
344343

345-
@classmethod
346-
def __get_validators__(cls) -> Iterator[Callable[[Any], Expr]]:
347-
"""Pydantic validators for this class."""
348-
yield cls._validate
349-
350344
@classmethod
351345
def __get_pydantic_core_schema__(
352346
cls, source: type, handler: GetCoreSchemaHandler

src/app_model/types/_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, Callable, Generic, Optional, TypeVar, Union
22

3-
from pydantic_compat import Field, field_validator
3+
from pydantic import Field, field_validator
44

55
from ._command_rule import CommandRule
66
from ._keybinding_rule import KeyBindingRule

src/app_model/types/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import TYPE_CHECKING, ClassVar
22

3-
from pydantic_compat import BaseModel
3+
from pydantic import BaseModel
44

55
if TYPE_CHECKING:
66
from pydantic import ConfigDict

src/app_model/types/_command_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Callable, Optional, Union
22

3-
from pydantic_compat import Field
3+
from pydantic import Field
44

55
from app_model import expressions
66

src/app_model/types/_icon.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from collections.abc import Generator
2-
from typing import Any, Callable, Optional, TypedDict, Union
1+
from typing import Any, Optional, TypedDict, Union
32

4-
from pydantic_compat import Field, model_validator
3+
from pydantic import Field, model_validator
54

65
from ._base import _BaseModel
76

@@ -30,10 +29,6 @@ class Icon(_BaseModel):
3029
" keys, such as `fa6s.arrow_down`",
3130
)
3231

33-
@classmethod
34-
def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]:
35-
yield cls._validate
36-
3732
@classmethod
3833
def _validate(cls, v: Any) -> "Icon":
3934
"""Validate icon."""

src/app_model/types/_keybinding_rule.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Callable, Optional, TypedDict, TypeVar, Union
22

3-
from pydantic_compat import PYDANTIC2, Field, model_validator
3+
from pydantic import Field, model_validator
44

55
from app_model import expressions
66

@@ -63,30 +63,14 @@ def _bind_to_current_platform(self) -> Optional[KeyEncoding]:
6363
return self.linux
6464
return self.primary
6565

66-
# These methods are here to make KeyBindingRule work as a field
67-
# there are better ways to do this now with pydantic v2... but it still
68-
# feels a bit in flux. pydantic_compat might not yet work for this (or
69-
# at least in my playing around i couldn't get it)
70-
# so sticking with this one conditional method here...
71-
if PYDANTIC2:
72-
# for v2
73-
@model_validator(mode="wrap")
74-
@classmethod
75-
def _model_val(
76-
cls: type[M], v: Any, handler: Callable[[Any], M]
77-
) -> "KeyBindingRule":
78-
if isinstance(v, StandardKeyBinding):
79-
return v.to_keybinding_rule()
80-
return handler(v) # type: ignore
81-
82-
else:
83-
84-
@classmethod
85-
def validate(cls, value: Any) -> "KeyBindingRule":
86-
"""Validate keybinding rule."""
87-
if isinstance(value, StandardKeyBinding):
88-
return value.to_keybinding_rule()
89-
return super().validate(value)
66+
@model_validator(mode="wrap")
67+
@classmethod
68+
def _model_val(
69+
cls: type[M], v: Any, handler: Callable[[Any], M]
70+
) -> "KeyBindingRule":
71+
if isinstance(v, StandardKeyBinding):
72+
return v.to_keybinding_rule()
73+
return handler(v) # type: ignore
9074

9175

9276
class KeyBindingRuleDict(TypedDict, total=False):

src/app_model/types/_keys/_key_codes.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ def from_event_code(cls, event_code: int) -> 'KeyCode':
199199
"""
200200
return _EVENTCODE_TO_KEYCODE.get(event_code, KeyCode.UNKNOWN)
201201

202-
@classmethod
203-
def __get_validators__(cls) -> Generator[Callable[..., 'KeyCode'], None, None]:
204-
yield cls.validate
205202

206203
@classmethod
207204
def __get_pydantic_core_schema__(

src/app_model/types/_keys/_keybindings.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import re
2-
from collections.abc import Generator
3-
from typing import TYPE_CHECKING, Any, Callable, Optional
2+
from typing import TYPE_CHECKING, Any, Optional
43

5-
from pydantic_compat import PYDANTIC2, BaseModel, Field, model_validator
4+
from pydantic import BaseModel, Field, model_validator
65

76
from app_model.types._constants import OperatingSystem
87

@@ -166,7 +165,7 @@ def _model_val(cls, instance: "SimpleKeyBinding") -> "SimpleKeyBinding":
166165
return cls._parse_input(instance)
167166

168167

169-
MIN1 = {"min_length": 1} if PYDANTIC2 else {"min_items": 1}
168+
MIN1 = {"min_length": 1}
170169

171170

172171
class KeyBinding:
@@ -277,10 +276,6 @@ def __int__(self) -> int:
277276
def __hash__(self) -> int:
278277
return hash(tuple(self.parts))
279278

280-
@classmethod
281-
def __get_validators__(cls) -> Generator[Callable[..., Any], None, None]:
282-
yield cls.validate # pragma: no cover
283-
284279
@classmethod
285280
def __get_pydantic_core_schema__(
286281
cls, source: type, handler: "GetCoreSchemaHandler"

0 commit comments

Comments
 (0)