File tree 3 files changed +15
-17
lines changed
3 files changed +15
-17
lines changed Original file line number Diff line number Diff line change @@ -169,8 +169,8 @@ def _create_class(cls: Type[_Model]) -> Type[_Model]:
169
169
}
170
170
171
171
# Inject model config extensions
172
+ model_config = ModelConfigWrapper .create (cls , namespace )
172
173
if chat_message_input_disabled is not None :
173
- model_config = ModelConfigWrapper .create (cls , namespace )
174
174
model_config ["chat_message_input_disabled" ] = (
175
175
chat_message_input_disabled
176
176
)
Original file line number Diff line number Diff line change @@ -90,12 +90,10 @@ def create(
90
90
cls , base_cls : Optional [Type [_Model ]], namespace : Dict [str , Any ]
91
91
) -> ModelConfigBase :
92
92
if (config_cls := namespace .get ("Config" )) is None :
93
- if base_cls :
94
- conf_base_cls = getattr (cls , "Config" , None )
95
- else :
96
- conf_base_cls = None
93
+ conf_base_cls = (
94
+ None if base_cls is None else getattr (base_cls , "Config" , None )
95
+ )
97
96
98
- # FIXME: add tests to confirm that the inheritance works
99
97
config_cls = type ("Config" , (conf_base_cls or object ,), {})
100
98
101
99
if module := namespace .get ("__module__" ):
@@ -128,8 +126,15 @@ def schema_extra_field(self) -> str:
128
126
def create (
129
127
cls , base_cls : Optional [Type [_Model ]], namespace : Dict [str , Any ]
130
128
) -> ModelConfigBase :
131
- # FIXME: merge with the existing "base_cls.model_config"
132
- model_config = namespace ["model_config" ] = (
133
- namespace .get ("model_config" ) or {}
129
+ base_model_config = (
130
+ {} if base_cls is None else getattr (base_cls , "model_config" , {})
134
131
)
132
+
133
+ curr_model_config = namespace .get ("model_config" ) or {}
134
+
135
+ model_config = namespace ["model_config" ] = {
136
+ ** base_model_config ,
137
+ ** curr_model_config ,
138
+ }
139
+
135
140
return cls (model_config )
Original file line number Diff line number Diff line change @@ -239,11 +239,6 @@ def test_configuration_parsing_two_buttons_success():
239
239
240
240
241
241
def test_dynamic_configuration_input_disabled_static ():
242
- """
243
- This test checks that DIAL specific features
244
- aren't inherited from the vanilla BaseModel class.
245
- """
246
-
247
242
class Conf (BaseModel ):
248
243
if PYDANTIC_V2 :
249
244
model_config = ConfigDict (chat_message_input_disabled = True )
@@ -254,13 +249,12 @@ class Config:
254
249
255
250
conf = form ()(Conf )
256
251
257
- assert model_json_schema (conf ).get ("dial:chatMessageInputDisabled" ) is None
252
+ assert model_json_schema (conf ).get ("dial:chatMessageInputDisabled" ) is True
258
253
259
254
260
255
def test_dynamic_configuration_input_disabled_dynamic ():
261
256
class Conf (BaseModel ):
262
257
if PYDANTIC_V2 :
263
- # FIXME: fix type ignore
264
258
model_config = ConfigDict (extra = "forbid" ) # type: ignore
265
259
else :
266
260
@@ -275,7 +269,6 @@ class Config:
275
269
def test_dynamic_configuration_input_disabled_omitted ():
276
270
class Conf (BaseModel ):
277
271
if PYDANTIC_V2 :
278
- # FIXME: fix type ignore
279
272
model_config = ConfigDict (extra = "forbid" ) # type: ignore
280
273
else :
281
274
You can’t perform that action at this time.
0 commit comments