dchvn commented on a change in pull request #34363:
URL: https://github.com/apache/spark/pull/34363#discussion_r744059673



##########
File path: python/pyspark/accumulators.py
##########
@@ -176,44 +193,44 @@ class AccumulatorParam(object):
     [7.0, 8.0, 9.0]
     """
 
-    def zero(self, value):
+    def zero(self, value: T) -> T:
         """
         Provide a "zero value" for the type, compatible in dimensions with the
         provided `value` (e.g., a zero vector)
         """
         raise NotImplementedError
 
-    def addInPlace(self, value1, value2):
+    def addInPlace(self, value1: T, value2: T) -> T:
         """
         Add two values of the accumulator's data type, returning a new value;
         for efficiency, can also update `value1` in place and return it.
         """
         raise NotImplementedError
 
 
-class AddingAccumulatorParam(AccumulatorParam):
+class AddingAccumulatorParam(AccumulatorParam[U]):
 
     """
     An AccumulatorParam that uses the + operators to add values. Designed for 
simple types
     such as integers, floats, and lists. Requires the zero value for the 
underlying type
     as a parameter.
     """
 
-    def __init__(self, zero_value):
+    def __init__(self, zero_value: U):
         self.zero_value = zero_value
 
-    def zero(self, value):
+    def zero(self, value: U) -> U:
         return self.zero_value
 
-    def addInPlace(self, value1, value2):
+    def addInPlace(self, value1: U, value2: U) -> U:
         value1 += value2

Review comment:
       > Why do we need ```__add__``` in SupportsIAdd?
   
   add ```__add__``` resolve error ```Unsupported left operand type for + ("U") 
 [operator]``` of this expression. I guess ```__iadd__``` need ```__add__``` as 
```value1 += value2``` is equivalent to the expression ```value1 = value1 + 
value2``` @xinrong-databricks 
   
   > Also, why this change of signature?
   
   I think we need type ```U``` for ```value1```. If we use ```SupportsIAdd```, 
we will get the error 
   ```Incompatible types in assignment (expression has type "SupportsIAdd", 
variable has type "U")  [assignment]``` @zero323 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to