Skip to content

Commit

Permalink
fix: fix pydantic 2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Nov 21, 2024
1 parent 74f4e0a commit 07d3592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ classifiers = [
"Programming Language :: Python :: 3.12",
]
dynamic = ["version"]
dependencies = ["pydantic >=1.10.0", "pydantic-compat >=0.1.0", "xsdata >=23.6,<24.4"]
dependencies = [
"pydantic >=1.10.16, !=2.0.*, !=2.1.*, !=2.2.*, !=2.3.*",
"pydantic-compat >=0.1.0",
"xsdata >=23.6,<24.4",
]

[project.urls]
Source = "https://github.com/tlambert03/ome-types"
Expand Down
11 changes: 8 additions & 3 deletions src/ome_types/_pydantic_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
if TYPE_CHECKING:
from pydantic.fields import FieldInfo

pydantic_version: tuple[int, ...] = tuple(
int(x) for x in pydantic.version.VERSION.split(".")[:2]
)

if pydantic.version.VERSION.startswith("2"):

if pydantic_version >= (2,):
try:
from pydantic_extra_types.color import Color as Color
except ImportError:
Expand All @@ -29,9 +33,10 @@ def field_regex(obj: type[BaseModel], field_name: str) -> str | None:
return meta.get("pattern") # type: ignore
return None

def get_default(f: FieldInfo) -> Any:
return f.get_default(call_default_factory=True)
kw: dict = {"validated_data": {}} if pydantic_version >= (2, 10) else {}

def get_default(f: FieldInfo) -> Any:
return f.get_default(call_default_factory=True, **kw)
else:
from pydantic.color import Color as Color # type: ignore [no-redef]

Expand Down

0 comments on commit 07d3592

Please sign in to comment.