Skip to content

Commit

Permalink
fix typings for pydantic 2.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
devkral committed Nov 22, 2024
1 parent 2703df1 commit 5a7878f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions edgy/core/db/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
from .types import BaseModelType

if TYPE_CHECKING:
from pydantic.fields import FieldInfo

from edgy.core.connection.database import Database
from edgy.core.db.fields.types import BaseFieldType
from edgy.core.db.models.model import Model
Expand Down Expand Up @@ -433,14 +431,14 @@ def __setattr__(self, key: str, value: Any) -> None:
field.__set__(self, value)
else:
for k, v in field.to_model(key, value).items():
if k in cast(dict[str, "FieldInfo"], self.__class__.model_fields):
if k in type(self).model_fields:
# __dict__ is updated and validator is executed
super().__setattr__(k, v)
else:
# bypass __setattr__ method
# ensures, __dict__ is updated
object.__setattr__(self, k, v)
elif key in cast(dict[str, "FieldInfo"], self.__class__.model_fields):
elif key in type(self).model_fields:
# __dict__ is updated and validator is executed
super().__setattr__(key, value)
else:
Expand Down
2 changes: 1 addition & 1 deletion edgy/core/db/models/metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def __new__(
new_class.__pydantic_fields__ = model_fields
# error since pydantic 2.10
with contextlib.suppress(AttributeError):
new_class.model_fields = model_fields # type: ignore
new_class.model_fields = model_fields
new_class._db_schemas = {}

# Set the owner of the field, must be done as early as possible
Expand Down
2 changes: 1 addition & 1 deletion edgy/core/marshalls/metaclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __new__(cls, name: str, bases: tuple[type, ...], attrs: dict[str, Any]) -> A
model_class.__pydantic_fields__ = model_fields
# error since pydantic 2.10
with contextlib.suppress(AttributeError):
model_class.model_fields = model_fields # type: ignore
model_class.model_fields = model_fields

# Handle annotations
annotations: dict[str, Any] = handle_annotations(bases, base_annotations, attrs)
Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ serve = "mkdocs serve --dev-addr localhost:8000"
# required for cli tests and check_types
features = ["all", "testing"]
# for typings
extra-dependencies = ["pydantic>=2.10"]
extra-dependencies = ["pydantic>=2.10.1"]


[tool.hatch.envs.test.env-vars]
Expand All @@ -137,8 +137,7 @@ EDGY_TESTCLIENT_USE_EXISTING = "true"


[tool.hatch.envs.test.scripts]
# cache-dir=null works around a pydantic 2.10 bug
check_types = "mypy -p edgy --cache-dir=null {args}"
check_types = "mypy -p edgy {args}"

[tool.hatch.envs.hatch-test]
# needs docker services running
Expand Down

0 comments on commit 5a7878f

Please sign in to comment.