|
1 | 1 | from typing import Any, Callable, Optional, TypedDict, TypeVar, Union |
2 | 2 |
|
3 | | -from pydantic_compat import PYDANTIC2, Field, model_validator |
| 3 | +from pydantic import Field, model_validator |
4 | 4 |
|
5 | 5 | from app_model import expressions |
6 | 6 |
|
@@ -63,30 +63,14 @@ def _bind_to_current_platform(self) -> Optional[KeyEncoding]: |
63 | 63 | return self.linux |
64 | 64 | return self.primary |
65 | 65 |
|
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 |
90 | 74 |
|
91 | 75 |
|
92 | 76 | class KeyBindingRuleDict(TypedDict, total=False): |
|
0 commit comments