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 @@ -204,14 +204,14 @@ def __str__(self) -> str:
204
204
@classmethod
205
205
@override
206
206
def construct ( # pyright: ignore[reportIncompatibleMethodOverride]
207
- cls : Type [ModelT ],
207
+ __cls : Type [ModelT ],
208
208
_fields_set : set [str ] | None = None ,
209
209
** values : object ,
210
210
) -> ModelT :
211
- m = cls .__new__ (cls )
211
+ m = __cls .__new__ (__cls )
212
212
fields_values : dict [str , object ] = {}
213
213
214
- config = get_model_config (cls )
214
+ config = get_model_config (__cls )
215
215
populate_by_name = (
216
216
config .allow_population_by_field_name
217
217
if isinstance (config , _ConfigProtocol )
@@ -221,7 +221,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
221
221
if _fields_set is None :
222
222
_fields_set = set ()
223
223
224
- model_fields = get_model_fields (cls )
224
+ model_fields = get_model_fields (__cls )
225
225
for name , field in model_fields .items ():
226
226
key = field .alias
227
227
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