File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -179,14 +179,14 @@ def __str__(self) -> str:
179
179
@classmethod
180
180
@override
181
181
def construct ( # pyright: ignore[reportIncompatibleMethodOverride]
182
- cls : Type [ModelT ],
182
+ __cls : Type [ModelT ],
183
183
_fields_set : set [str ] | None = None ,
184
184
** values : object ,
185
185
) -> ModelT :
186
- m = cls .__new__ (cls )
186
+ m = __cls .__new__ (__cls )
187
187
fields_values : dict [str , object ] = {}
188
188
189
- config = get_model_config (cls )
189
+ config = get_model_config (__cls )
190
190
populate_by_name = (
191
191
config .allow_population_by_field_name
192
192
if isinstance (config , _ConfigProtocol )
@@ -196,7 +196,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
196
196
if _fields_set is None :
197
197
_fields_set = set ()
198
198
199
- model_fields = get_model_fields (cls )
199
+ model_fields = get_model_fields (__cls )
200
200
for name , field in model_fields .items ():
201
201
key = field .alias
202
202
if key is None or (key not in values and populate_by_name ):
Original file line number Diff line number Diff line change @@ -844,3 +844,13 @@ class Model(BaseModel):
844
844
assert m .alias == "foo"
845
845
assert isinstance (m .union , str )
846
846
assert m .union == "bar"
847
+
848
+
849
+ @pytest .mark .skipif (not PYDANTIC_V2 , reason = "TypeAliasType is not supported in Pydantic v1" )
850
+ def test_field_named_cls () -> None :
851
+ class Model (BaseModel ):
852
+ cls : str
853
+
854
+ m = construct_type (value = {"cls" : "foo" }, type_ = Model )
855
+ assert isinstance (m , Model )
856
+ assert isinstance (m .cls , str )
You can’t perform that action at this time.
0 commit comments