Skip to content

Commit d792335

Browse files
fix(compat): compat with pydantic<2.8.0 when using additional fields
1 parent d9de5e4 commit d792335

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/hyperspell/types/memory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ class Metadata(BaseModel):
3232

3333
url: Optional[str] = None
3434

35-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
3635
if TYPE_CHECKING:
36+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
37+
# value to this field, so for compatibility we avoid doing it at runtime.
38+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
39+
3740
# Stub to indicate that arbitrary properties are accepted.
3841
# To access properties that are not valid identifiers you can use `getattr`, e.g.
3942
# `getattr(obj, '$type')`
4043
def __getattr__(self, attr: str) -> object: ...
44+
else:
45+
__pydantic_extra__: Dict[str, object]
4146

4247

4348
class Memory(BaseModel):

0 commit comments

Comments
 (0)