diff --git a/b2/_internal/_cli/obj_loads.py b/b2/_internal/_cli/obj_loads.py index de4a71ae..d7dd3b67 100644 --- a/b2/_internal/_cli/obj_loads.py +++ b/b2/_internal/_cli/obj_loads.py @@ -10,6 +10,7 @@ from __future__ import annotations import argparse +import copy import io import json import logging @@ -53,10 +54,20 @@ def describe_type(type_) -> str: _UNDEF = object() +def type_with_config(type_: type[T], config: pydantic.ConfigDict) -> type[T]: + type_ = copy.copy(type_) + if not hasattr(type_, '__config__'): + type_.__pydantic_config__ = config + else: + type_.__config__ = type_.__config__.copy() + type_.__config__.update(config) + return type_ + + def validated_loads(data: str, expected_type: type[T] | None = None) -> T: val = _UNDEF if expected_type is not None and pydantic is not None: - expected_type = pydantic.with_config(pydantic.ConfigDict(extra="allow"))(expected_type) + expected_type = type_with_config(expected_type, pydantic.ConfigDict(extra="allow")) try: ta = TypeAdapter(expected_type) except TypeError: