1- # This code is based on code from Apache Spark under the license found in the LICENSE # noqa: D100
1+ # ruff: noqa: D100
2+ # This code is based on code from Apache Spark under the license found in the LICENSE
23# file located in the 'spark' folder.
34
45import calendar
1112from typing import (
1213 Any ,
1314 ClassVar ,
15+ NoReturn ,
1416 Optional ,
1517 TypeVar ,
1618 Union ,
@@ -102,11 +104,11 @@ def needConversion(self) -> bool:
102104 """
103105 return False
104106
105- def toInternal (self , obj : Any ) -> Any :
107+ def toInternal (self , obj : Any ) -> Any : # noqa: ANN401
106108 """Converts a Python object into an internal SQL object."""
107109 return obj
108110
109- def fromInternal (self , obj : Any ) -> Any :
111+ def fromInternal (self , obj : Any ) -> Any : # noqa: ANN401
110112 """Converts an internal SQL object into a native Python object."""
111113 return obj
112114
@@ -889,7 +891,7 @@ def simpleString(self) -> str: # noqa: D102
889891 def __repr__ (self ) -> str : # noqa: D105
890892 return "StructType([%s])" % ", " .join (str (field ) for field in self )
891893
892- def __contains__ (self , item : Any ) -> bool : # noqa: D105
894+ def __contains__ (self , item : str ) -> bool : # noqa: D105
893895 return item in self .names
894896
895897 def extract_types_and_names (self ) -> tuple [list [str ], list [str ]]: # noqa: D102
@@ -1010,21 +1012,21 @@ def _cachedSqlType(cls) -> DataType:
10101012 cls ._cached_sql_type = cls .sqlType () # type: ignore[attr-defined]
10111013 return cls ._cached_sql_type # type: ignore[attr-defined]
10121014
1013- def toInternal (self , obj : Any ) -> Any :
1015+ def toInternal (self , obj : Any ) -> Any : # noqa: ANN401
10141016 if obj is not None :
10151017 return self ._cachedSqlType ().toInternal (self .serialize (obj ))
10161018
1017- def fromInternal (self , obj : Any ) -> Any :
1019+ def fromInternal (self , obj : Any ) -> Any : # noqa: ANN401
10181020 v = self ._cachedSqlType ().fromInternal (obj )
10191021 if v is not None :
10201022 return self .deserialize (v )
10211023
1022- def serialize (self , obj : Any ) -> Any :
1024+ def serialize (self , obj : Any ) -> NoReturn : # noqa: ANN401
10231025 """Converts a user-type object into a SQL datum."""
10241026 msg = "UDT must implement toInternal()."
10251027 raise NotImplementedError (msg )
10261028
1027- def deserialize (self , datum : Any ) -> Any :
1029+ def deserialize (self , datum : Any ) -> NoReturn : # noqa: ANN401
10281030 """Converts a SQL datum into a user-type object."""
10291031 msg = "UDT must implement fromInternal()."
10301032 raise NotImplementedError (msg )
@@ -1132,7 +1134,7 @@ class Row(tuple):
11321134 def __new__ (cls , * args : str ) -> "Row" : ...
11331135
11341136 @overload
1135- def __new__ (cls , ** kwargs : Any ) -> "Row" : ...
1137+ def __new__ (cls , ** kwargs : Any ) -> "Row" : ... # noqa: ANN401
11361138
11371139 def __new__ (cls , * args : Optional [str ], ** kwargs : Optional [Any ]) -> "Row" : # noqa: D102
11381140 if args and kwargs :
@@ -1179,7 +1181,7 @@ def asDict(self, recursive: bool = False) -> dict[str, Any]:
11791181
11801182 if recursive :
11811183
1182- def conv (obj : Any ) -> Any :
1184+ def conv (obj : Row | list | dict | object ) -> list | dict | object :
11831185 if isinstance (obj , Row ):
11841186 return obj .asDict (True )
11851187 elif isinstance (obj , list ):
@@ -1193,22 +1195,22 @@ def conv(obj: Any) -> Any:
11931195 else :
11941196 return dict (zip (self .__fields__ , self ))
11951197
1196- def __contains__ (self , item : Any ) -> bool : # noqa: D105
1198+ def __contains__ (self , item : Any ) -> bool : # noqa: D105, ANN401
11971199 if hasattr (self , "__fields__" ):
11981200 return item in self .__fields__
11991201 else :
12001202 return super (Row , self ).__contains__ (item )
12011203
12021204 # let object acts like class
1203- def __call__ (self , * args : Any ) -> "Row" :
1205+ def __call__ (self , * args : Any ) -> "Row" : # noqa: ANN401
12041206 """Create new Row object."""
12051207 if len (args ) > len (self ):
12061208 raise ValueError (
12071209 "Can not create Row with fields %s, expected %d values but got %s" % (self , len (self ), args )
12081210 )
12091211 return _create_row (self , args )
12101212
1211- def __getitem__ (self , item : Any ) -> Any : # noqa: D105
1213+ def __getitem__ (self , item : Any ) -> Any : # noqa: D105, ANN401
12121214 if isinstance (item , (int , slice )):
12131215 return super (Row , self ).__getitem__ (item )
12141216 try :
@@ -1221,7 +1223,7 @@ def __getitem__(self, item: Any) -> Any: # noqa: D105
12211223 except ValueError :
12221224 raise ValueError (item )
12231225
1224- def __getattr__ (self , item : str ) -> Any : # noqa: D105
1226+ def __getattr__ (self , item : str ) -> Any : # noqa: D105, ANN401
12251227 if item .startswith ("__" ):
12261228 raise AttributeError (item )
12271229 try :
@@ -1234,7 +1236,7 @@ def __getattr__(self, item: str) -> Any: # noqa: D105
12341236 except ValueError :
12351237 raise AttributeError (item )
12361238
1237- def __setattr__ (self , key : Any , value : Any ) -> None : # noqa: D105
1239+ def __setattr__ (self , key : Any , value : Any ) -> None : # noqa: D105, ANN401
12381240 if key != "__fields__" :
12391241 msg = "Row is read-only"
12401242 raise RuntimeError (msg )
0 commit comments