Skip to content

Commit 662246b

Browse files
fix(compat): compat with pydantic<2.8.0 when using additional fields
1 parent 74f0fa2 commit 662246b

File tree

1 file changed

+60
-10
lines changed

1 file changed

+60
-10
lines changed

src/opencode_ai/types/config.py

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@ class AgentBuild(BaseModel):
7777

7878
top_p: Optional[float] = None
7979

80-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
8180
if TYPE_CHECKING:
81+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
82+
# value to this field, so for compatibility we avoid doing it at runtime.
83+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
84+
8285
# Stub to indicate that arbitrary properties are accepted.
8386
# To access properties that are not valid identifiers you can use `getattr`, e.g.
8487
# `getattr(obj, '$type')`
8588
def __getattr__(self, attr: str) -> object: ...
89+
else:
90+
__pydantic_extra__: Dict[str, object]
8691

8792

8893
class AgentGeneralPermission(BaseModel):
@@ -113,12 +118,17 @@ class AgentGeneral(BaseModel):
113118

114119
top_p: Optional[float] = None
115120

116-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
117121
if TYPE_CHECKING:
122+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
123+
# value to this field, so for compatibility we avoid doing it at runtime.
124+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
125+
118126
# Stub to indicate that arbitrary properties are accepted.
119127
# To access properties that are not valid identifiers you can use `getattr`, e.g.
120128
# `getattr(obj, '$type')`
121129
def __getattr__(self, attr: str) -> object: ...
130+
else:
131+
__pydantic_extra__: Dict[str, object]
122132

123133

124134
class AgentPlanPermission(BaseModel):
@@ -149,12 +159,17 @@ class AgentPlan(BaseModel):
149159

150160
top_p: Optional[float] = None
151161

152-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
153162
if TYPE_CHECKING:
163+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
164+
# value to this field, so for compatibility we avoid doing it at runtime.
165+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
166+
154167
# Stub to indicate that arbitrary properties are accepted.
155168
# To access properties that are not valid identifiers you can use `getattr`, e.g.
156169
# `getattr(obj, '$type')`
157170
def __getattr__(self, attr: str) -> object: ...
171+
else:
172+
__pydantic_extra__: Dict[str, object]
158173

159174

160175
class AgentAgentItemPermission(BaseModel):
@@ -185,12 +200,17 @@ class AgentAgentItem(BaseModel):
185200

186201
top_p: Optional[float] = None
187202

188-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
189203
if TYPE_CHECKING:
204+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
205+
# value to this field, so for compatibility we avoid doing it at runtime.
206+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
207+
190208
# Stub to indicate that arbitrary properties are accepted.
191209
# To access properties that are not valid identifiers you can use `getattr`, e.g.
192210
# `getattr(obj, '$type')`
193211
def __getattr__(self, attr: str) -> object: ...
212+
else:
213+
__pydantic_extra__: Dict[str, object]
194214

195215

196216
class Agent(BaseModel):
@@ -200,12 +220,17 @@ class Agent(BaseModel):
200220

201221
plan: Optional[AgentPlan] = None
202222

203-
__pydantic_extra__: Dict[str, AgentAgentItem] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
204223
if TYPE_CHECKING:
224+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
225+
# value to this field, so for compatibility we avoid doing it at runtime.
226+
__pydantic_extra__: Dict[str, AgentAgentItem] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
227+
205228
# Stub to indicate that arbitrary properties are accepted.
206229
# To access properties that are not valid identifiers you can use `getattr`, e.g.
207230
# `getattr(obj, '$type')`
208231
def __getattr__(self, attr: str) -> AgentAgentItem: ...
232+
else:
233+
__pydantic_extra__: Dict[str, AgentAgentItem]
209234

210235

211236
class Command(BaseModel):
@@ -299,12 +324,17 @@ class ModeBuild(BaseModel):
299324

300325
top_p: Optional[float] = None
301326

302-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
303327
if TYPE_CHECKING:
328+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
329+
# value to this field, so for compatibility we avoid doing it at runtime.
330+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
331+
304332
# Stub to indicate that arbitrary properties are accepted.
305333
# To access properties that are not valid identifiers you can use `getattr`, e.g.
306334
# `getattr(obj, '$type')`
307335
def __getattr__(self, attr: str) -> object: ...
336+
else:
337+
__pydantic_extra__: Dict[str, object]
308338

309339

310340
class ModePlanPermission(BaseModel):
@@ -335,12 +365,17 @@ class ModePlan(BaseModel):
335365

336366
top_p: Optional[float] = None
337367

338-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
339368
if TYPE_CHECKING:
369+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
370+
# value to this field, so for compatibility we avoid doing it at runtime.
371+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
372+
340373
# Stub to indicate that arbitrary properties are accepted.
341374
# To access properties that are not valid identifiers you can use `getattr`, e.g.
342375
# `getattr(obj, '$type')`
343376
def __getattr__(self, attr: str) -> object: ...
377+
else:
378+
__pydantic_extra__: Dict[str, object]
344379

345380

346381
class ModeModeItemPermission(BaseModel):
@@ -371,25 +406,35 @@ class ModeModeItem(BaseModel):
371406

372407
top_p: Optional[float] = None
373408

374-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
375409
if TYPE_CHECKING:
410+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
411+
# value to this field, so for compatibility we avoid doing it at runtime.
412+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
413+
376414
# Stub to indicate that arbitrary properties are accepted.
377415
# To access properties that are not valid identifiers you can use `getattr`, e.g.
378416
# `getattr(obj, '$type')`
379417
def __getattr__(self, attr: str) -> object: ...
418+
else:
419+
__pydantic_extra__: Dict[str, object]
380420

381421

382422
class Mode(BaseModel):
383423
build: Optional[ModeBuild] = None
384424

385425
plan: Optional[ModePlan] = None
386426

387-
__pydantic_extra__: Dict[str, ModeModeItem] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
388427
if TYPE_CHECKING:
428+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
429+
# value to this field, so for compatibility we avoid doing it at runtime.
430+
__pydantic_extra__: Dict[str, ModeModeItem] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
431+
389432
# Stub to indicate that arbitrary properties are accepted.
390433
# To access properties that are not valid identifiers you can use `getattr`, e.g.
391434
# `getattr(obj, '$type')`
392435
def __getattr__(self, attr: str) -> ModeModeItem: ...
436+
else:
437+
__pydantic_extra__: Dict[str, ModeModeItem]
393438

394439

395440
class Permission(BaseModel):
@@ -449,12 +494,17 @@ class ProviderOptions(BaseModel):
449494
Default is 300000 (5 minutes). Set to false to disable timeout.
450495
"""
451496

452-
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
453497
if TYPE_CHECKING:
498+
# Some versions of Pydantic <2.8.0 have a bug and don’t allow assigning a
499+
# value to this field, so for compatibility we avoid doing it at runtime.
500+
__pydantic_extra__: Dict[str, object] = FieldInfo(init=False) # pyright: ignore[reportIncompatibleVariableOverride]
501+
454502
# Stub to indicate that arbitrary properties are accepted.
455503
# To access properties that are not valid identifiers you can use `getattr`, e.g.
456504
# `getattr(obj, '$type')`
457505
def __getattr__(self, attr: str) -> object: ...
506+
else:
507+
__pydantic_extra__: Dict[str, object]
458508

459509

460510
class Provider(BaseModel):

0 commit comments

Comments
 (0)