99from pydantic .fields import PydanticUndefined
1010
1111if TYPE_CHECKING : # pragma: no cover
12- from typing import Any
12+ from typing import Any , cast
1313
1414
1515class AttrDict (BaseModel , MutableMapping ): # noqa: PLW1641
@@ -103,6 +103,10 @@ def update( # type: ignore[override]
103103 ) -> None :
104104 if other and isinstance (other , Mapping ):
105105 for key , value in other .items ():
106+ if not isinstance (key , str ):
107+ raise TypeError (
108+ "Keys must be of type `str`, not " f"`{ type (key ).__name__ } `."
109+ )
106110 setattr (self , key , value )
107111 elif other and isinstance (other , BaseModel ):
108112 for key , value in other :
@@ -117,7 +121,11 @@ def update( # type: ignore[override]
117121 raise ValueError (
118122 "`other` must be an iterable of objects of length two."
119123 )
120- for key , value in other : # type: ignore[misc]
124+
125+ if TYPE_CHECKING : # pragma: no cover
126+ other = cast (Iterable [tuple [str , Any ]], other )
127+
128+ for key , value in other :
121129 setattr (self , key , value )
122130 elif other :
123131 raise TypeError (
0 commit comments