zero323 commented on pull request #34466:
URL: https://github.com/apache/spark/pull/34466#issuecomment-957327097


   >     1. I used lots of "cast" to cancel the error, but is there other 
better way?
   
   I see that these are primarily related to union attributes. We have ongoing 
discussion about this, so it is not a binding opinion, but if it is repeated 
usage within the same block you can try asserting at the beginning:
   
   ```python
   assert self._jvm is not None
   ...
   self._jvm.PythonUtils.getPythonAuthSocketTimeout(self._jsc)
   ```
   
   or extract local variable with single ignore or cast
   
   ```python
   jvm = cast(JVMView, self._jvm)
   
   jvm.PythonUtils.getPythonAuthSocketTimeout(self._jsc)
   ```
   
   In a long run, we might consider adding some helpers to handle such case. 
Maybe something like this? 
   
   ```python
       @property
       def _jvm(self) -> JVMView:
           jvm = SparkContext._jvm
           assert jvm is not None
           return jvm
   ```
   
   It is definitely not in the scope of this PR though.


-- 
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