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 @@ -204,14 +204,14 @@ def __str__(self) -> str:
204204 @classmethod
205205 @override
206206 def construct ( # pyright: ignore[reportIncompatibleMethodOverride]
207- cls : Type [ModelT ],
207+ __cls : Type [ModelT ],
208208 _fields_set : set [str ] | None = None ,
209209 ** values : object ,
210210 ) -> ModelT :
211- m = cls .__new__ (cls )
211+ m = __cls .__new__ (__cls )
212212 fields_values : dict [str , object ] = {}
213213
214- config = get_model_config (cls )
214+ config = get_model_config (__cls )
215215 populate_by_name = (
216216 config .allow_population_by_field_name
217217 if isinstance (config , _ConfigProtocol )
@@ -221,7 +221,7 @@ def construct( # pyright: ignore[reportIncompatibleMethodOverride]
221221 if _fields_set is None :
222222 _fields_set = set ()
223223
224- model_fields = get_model_fields (cls )
224+ model_fields = get_model_fields (__cls )
225225 for name , field in model_fields .items ():
226226 key = field .alias
227227 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