File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 1
1
configured_endpoints : 1254
2
- openapi_spec_url : https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-21c3f4e3559582f365d9afb16ec8ccfadc79aa7fd5c5d295a3f1bebfa28765ca .yml
2
+ openapi_spec_url : https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-ca12a5056d3bb298068f1638207e72d7ea56d56fa0fbdcbcdfc1c57f6b253f14 .yml
Original file line number Diff line number Diff line change 10
10
ClassVar ,
11
11
Protocol ,
12
12
Required ,
13
+ ParamSpec ,
13
14
TypedDict ,
14
15
TypeGuard ,
15
16
final ,
67
68
__all__ = ["BaseModel" , "GenericModel" ]
68
69
69
70
_T = TypeVar ("_T" )
71
+ _BaseModelT = TypeVar ("_BaseModelT" , bound = "BaseModel" )
72
+
73
+ P = ParamSpec ("P" )
70
74
71
75
72
76
@runtime_checkable
@@ -379,6 +383,29 @@ def is_basemodel_type(type_: type) -> TypeGuard[type[BaseModel] | type[GenericMo
379
383
return issubclass (origin , BaseModel ) or issubclass (origin , GenericModel )
380
384
381
385
386
+ def build (
387
+ base_model_cls : Callable [P , _BaseModelT ],
388
+ * args : P .args ,
389
+ ** kwargs : P .kwargs ,
390
+ ) -> _BaseModelT :
391
+ """Construct a BaseModel class without validation.
392
+
393
+ This is useful for cases where you need to instantiate a `BaseModel`
394
+ from an API response as this provides type-safe params which isn't supported
395
+ by helpers like `construct_type()`.
396
+
397
+ ```py
398
+ build(MyModel, my_field_a="foo", my_field_b=123)
399
+ ```
400
+ """
401
+ if args :
402
+ raise TypeError (
403
+ "Received positional arguments which are not supported; Keyword arguments must be used instead" ,
404
+ )
405
+
406
+ return cast (_BaseModelT , construct_type (type_ = base_model_cls , value = kwargs ))
407
+
408
+
382
409
def construct_type (* , value : object , type_ : object ) -> object :
383
410
"""Loose coercion to the expected type with construction of nested values.
384
411
You can’t perform that action at this time.
0 commit comments