Skip to content

Commit 5d95ecf

Browse files
fix(compat): compat with pydantic<2.8.0 when using additional fields
1 parent 9c4b995 commit 5d95ecf

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/openai/types/evals/runs/output_item_list_response.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ class Result(BaseModel):
2727
type: Optional[str] = None
2828
"""The grader type (for example, "string-check-grader")."""
2929

30-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
3130
if TYPE_CHECKING:
31+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
32+
# value to this field, so for compatibility we avoid doing it at runtime.
33+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
34+
3235
# Stub to indicate that arbitrary properties are accepted.
3336
# To access properties that are not valid identifiers you can use `getattr`, e.g.
3437
# `getattr(obj, '$type')`
3538
def __getattr__(self, attr: str) -> object: ...
39+
else:
40+
__pydantic_extra__: Dict[str, object]
3641

3742

3843
class SampleInput(BaseModel):

src/openai/types/evals/runs/output_item_retrieve_response.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ class Result(BaseModel):
2727
type: Optional[str] = None
2828
"""The grader type (for example, "string-check-grader")."""
2929

30-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
3130
if TYPE_CHECKING:
31+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
32+
# value to this field, so for compatibility we avoid doing it at runtime.
33+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
34+
3235
# Stub to indicate that arbitrary properties are accepted.
3336
# To access properties that are not valid identifiers you can use `getattr`, e.g.
3437
# `getattr(obj, '$type')`
3538
def __getattr__(self, attr: str) -> object: ...
39+
else:
40+
__pydantic_extra__: Dict[str, object]
3641

3742

3843
class SampleInput(BaseModel):

0 commit comments

Comments
 (0)