@@ -648,6 +648,8 @@ def _resolve_subgroups(
648
648
if subgroup_field .subgroup_default is dataclasses .MISSING :
649
649
assert argument_options ["required" ]
650
650
elif isinstance (argument_options ["default" ], dict ):
651
+ # TODO: In this case here, the value of a nested subgroup in this default dict
652
+ # should also be used!
651
653
# BUG #276: The default here is a dict because it came from a config file.
652
654
# Here we want the subgroup field to have a 'str' default, because we just want
653
655
# to be able to choose between the subgroup names.
@@ -1196,29 +1198,6 @@ def _create_dataclass_instance(
1196
1198
return constructor (** constructor_args )
1197
1199
1198
1200
1199
- def _has_values_of_type (
1200
- mapping : Mapping [K , Any ], value_type : type [V ] | tuple [type [V ], ...]
1201
- ) -> TypeGuard [Mapping [K , V ]]:
1202
- # Utility functions used to narrow the type of dictionaries.
1203
- return all (isinstance (v , value_type ) for v in mapping .values ())
1204
-
1205
-
1206
- def _has_keys_of_type (
1207
- mapping : Mapping [Any , V ], key_type : type [K ] | tuple [type [K ], ...]
1208
- ) -> TypeGuard [Mapping [K , V ]]:
1209
- # Utility functions used to narrow the type of dictionaries.
1210
- return all (isinstance (k , key_type ) for k in mapping .keys ())
1211
-
1212
-
1213
- def _has_items_of_type (
1214
- mapping : Mapping [Any , Any ],
1215
- item_type : tuple [type [K ] | tuple [type [K ], ...], type [V ] | tuple [type [V ], ...]],
1216
- ) -> TypeGuard [Mapping [K , V ]]:
1217
- # Utility functions used to narrow the type of a dictionary or mapping.
1218
- key_type , value_type = item_type
1219
- return _has_keys_of_type (mapping , key_type ) and _has_values_of_type (mapping , value_type )
1220
-
1221
-
1222
1201
def _infer_subgroup_key_to_use_from_config (
1223
1202
default_in_config : dict [str , Any ],
1224
1203
# subgroup_default: Hashable,
@@ -1296,6 +1275,29 @@ def _infer_subgroup_key_to_use_from_config(
1296
1275
# }
1297
1276
1298
1277
1278
+ def _has_values_of_type (
1279
+ mapping : Mapping [K , Any ], value_type : type [V ] | tuple [type [V ], ...]
1280
+ ) -> TypeGuard [Mapping [K , V ]]:
1281
+ # Utility functions used to narrow the type of dictionaries.
1282
+ return all (isinstance (v , value_type ) for v in mapping .values ())
1283
+
1284
+
1285
+ def _has_keys_of_type (
1286
+ mapping : Mapping [Any , V ], key_type : type [K ] | tuple [type [K ], ...]
1287
+ ) -> TypeGuard [Mapping [K , V ]]:
1288
+ # Utility functions used to narrow the type of dictionaries.
1289
+ return all (isinstance (k , key_type ) for k in mapping .keys ())
1290
+
1291
+
1292
+ def _has_items_of_type (
1293
+ mapping : Mapping [Any , Any ],
1294
+ item_type : tuple [type [K ] | tuple [type [K ], ...], type [V ] | tuple [type [V ], ...]],
1295
+ ) -> TypeGuard [Mapping [K , V ]]:
1296
+ # Utility functions used to narrow the type of a dictionary or mapping.
1297
+ key_type , value_type = item_type
1298
+ return _has_keys_of_type (mapping , key_type ) and _has_values_of_type (mapping , value_type )
1299
+
1300
+
1299
1301
def _default_constructor_argument_values (
1300
1302
some_dataclass_type : type [Dataclass ] | functools .partial [Dataclass ],
1301
1303
) -> PossiblyNestedDict [str , Any ]:
0 commit comments