File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 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:
179179 @classmethod
180180 @override
181181 def construct ( # pyright: ignore[reportIncompatibleMethodOverride]
182- cls : Type [ModelT ],
182+ __cls : Type [ModelT ],
183183 _fields_set : set [str ] | None = None ,
184184 ** values : object ,
185185 ) -> ModelT :
186- m = cls .__new__ (cls )
186+ m = __cls .__new__ (__cls )
187187 fields_values : dict [str , object ] = {}
188188
189- config = get_model_config (cls )
189+ config = get_model_config (__cls )
190190 populate_by_name = (
191191 config .allow_population_by_field_name
192192 if isinstance (config , _ConfigProtocol )
@@ -196,7 +196,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
196196 if _fields_set is None :
197197 _fields_set = set ()
198198
199- model_fields = get_model_fields (cls )
199+ model_fields = get_model_fields (__cls )
200200 for name , field in model_fields .items ():
201201 key = field .alias
202202 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):
844844 assert m .alias == "foo"
845845 assert isinstance (m .union , str )
846846 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