This is an automated email from the ASF dual-hosted git repository.

gaogaotiantian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 95ebf4439a18 [SPARK-60185][PYTHON] Improve type annotation for 
SparkConnectGrpcException message
95ebf4439a18 is described below

commit 95ebf4439a18f2a8f1bc9a08bf6138fff1e7888e
Author: Tim Hsiung <[email protected]>
AuthorDate: Wed Oct 28 16:46:29 2026 -0700

    [SPARK-60185][PYTHON] Improve type annotation for SparkConnectGrpcException 
message
    
    ### What changes were proposed in this pull request?
    
    Keep `message` local while adding the optional reason prefix in 
`SparkConnectGrpcException.__init__`, and let the base constructor initialize 
`_message`. Remove the premature member assignment and its type ignore.
    
    ### Why are the changes needed?
    
    The input message may be `None`, while `_message` is a string. The base 
constructor already resolves a missing message from the error class and 
parameters, so assigning the optional input to the member first is unnecessary.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    - All 12 tests in `pyspark.errors.tests.test_connect_errors_conversion` 
passed.
    - Six constructor cases produced identical baseline/modified output, 
including absent/empty messages and reasons, error-class-based messages, and 
displayed server stacktraces.
    - Mypy on `python/pyspark/errors/exceptions/connect.py`, Ruff lint/format 
checks, and `git diff --check` passed.
    
    No new tests were added; validation used the existing suite and local 
equivalence probes.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: pi 1.1.0
    
    Closes #59395 from bearomorphism/typing-connect-exception-message.
    
    Authored-by: Tim Hsiung <[email protected]>
    Signed-off-by: Tian Gao <[email protected]>
---
 python/pyspark/errors/exceptions/connect.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/python/pyspark/errors/exceptions/connect.py 
b/python/pyspark/errors/exceptions/connect.py
index 794a9d7e73a7..5fdba1e40da4 100644
--- a/python/pyspark/errors/exceptions/connect.py
+++ b/python/pyspark/errors/exceptions/connect.py
@@ -316,9 +316,8 @@ class SparkConnectGrpcException(SparkConnectException):
     ) -> None:
         if contexts is None:
             contexts = []
-        self._message = message  # type: ignore[assignment]
         if reason is not None:
-            self._message = f"({reason}) {self._message}"
+            message = f"({reason}) {message}"
 
         # PySparkException has the assumption that errorClass and 
messageParameters are
         # only occurring together. If only one is set, we assume the message 
to be fully
@@ -331,7 +330,7 @@ class SparkConnectGrpcException(SparkConnectException):
             tmp_message_parameters = None
 
         super().__init__(
-            message=self._message,
+            message=message,
             errorClass=tmp_error_class,
             messageParameters=tmp_message_parameters,
         )


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

Reply via email to