[SPARK-56270][PYTHON] Fix type hints and import issue for find_spark_home#55067
Open
gaogaotiantian wants to merge 1 commit intoapache:masterfrom
Open
[SPARK-56270][PYTHON] Fix type hints and import issue for find_spark_home#55067gaogaotiantian wants to merge 1 commit intoapache:masterfrom
gaogaotiantian wants to merge 1 commit intoapache:masterfrom
Conversation
HyukjinKwon
approved these changes
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
find_spark_homemodule and fill in the type hintsImportErrorcheck andimport_error_raisedrelated logicWhy are the changes needed?
There's no reason we can't type hint this module so I just did it.
For the import part, it's impossible to trigger that path because
find_spec("pyspark")will never triggerImportError. It either returns a spec orNone. I searched the history and the first time it was introduced was in #15659 . There were 2 branches and the one for python2 actually will trigger theImportError. The python3 branch won't work but it might just be ignored.In #28152 we added
import_error_raisedcheck and extra messages, but we only tested in python2, which would trigger that message. I confirmed that the message won't be printed if we can't findpyspark.Now we print the message if we can't find
SPARK_HOME.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Locally confirmed the message will be printed if
pysparkcan't be imported. Lint also passed locally.Was this patch authored or co-authored using generative AI tooling?
No.