[SPARK-58410][PYTHON] Remove unnecessary type: ignore comments in the DataFrame read/write API - #57611
Open
Spenserrrr wants to merge 1 commit into
Open
[SPARK-58410][PYTHON] Remove unnecessary type: ignore comments in the DataFrame read/write API#57611Spenserrrr wants to merge 1 commit into
Spenserrrr wants to merge 1 commit into
Conversation
Contributor
Author
|
Hi @gaogaotiantian! This is a type: ignore cleanup, and could you take a look when you have a moment? Thank you so much! |
… DataFrame read/write API ### What changes were proposed in this pull request? Removes 7 `# type: ignore` comments in the PySpark DataFrame read/write API (DataFrameReader/DataFrameWriter and their streaming and Spark Connect variants) by improving the underlying annotations: 1. `OptionUtils._set_opts` (classic + Connect): declare a `SupportsOption` Protocol and annotate `self` with it, so `self.option(...)` type-checks without an `[attr-defined]` ignore. 2. `DataFrameReader.load` (Connect): declare `paths: Optional[List[str]]` up front instead of reusing the widely-typed `path` local, removing an `[arg-type]` ignore. 3. `DataStreamWriter.partitionBy` / `clusterBy` (classic + Connect): widen the overload implementation signatures to `*cols: Union[str, List[str]]` to match their overloads (and the non-streaming `DataFrameWriter`), and normalize into a `Sequence[str]` local, removing four `[misc]` ignores without adding new ones. ### Why are the changes needed? These ignores sit on fixable annotation gaps rather than genuine type deviations. Removing them documents the intended contracts and lets mypy type-check the affected code paths (e.g. the streaming `partitionBy` list branch was previously dead code to the type checker). ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests. Verified with mypy over the full `python/pyspark` scope. Generated-by: Claude Code (Opus 4.8)
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?
This PR removes 7 unnecessary
# type: ignorecomments in the PySpark DataFrame read/write API (DataFrameReader/DataFrameWriterand their streaming and Spark Connect variants) by improving the underlying annotations:OptionUtils._set_opts(classic + Connect) — the mixin callsself.option(...)without declaring that its host provides it, requiring a# type: ignore[attr-defined]. A smallSupportsOptionProtocolis added andselfis annotated with it, so the call type-checks and the contract is explicit. (The siblingself.schema(...)call keeps its ignore on purpose:schemais a reader-only method, but_set_optsis shared with writers, so requiringschemaonselfwould break the writer call sites.)DataFrameReader.load(Connect) — apathslocal was assigned from the wideOptional[Union[str, List[str]]]parameter and then reused across anisinstancenarrowing, so mypy kept the wide first-assignment type and needed a# type: ignore[arg-type]. Declaringpaths: Optional[List[str]]up front and normalizing the input removes the ignore and makes the None/str/list cases explicit.DataStreamWriter.partitionBy/clusterBy(classic + Connect) — the overload implementation signatures were*cols: str, which contradicts theList[str]overload and required# type: ignore[misc]; it also left the list-handling branch as dead code to the type checker. The implementation signatures are widened to*cols: Union[str, List[str]](matching the non-streamingDataFrameWriter), and the columns are normalized into a correctly typedSequence[str]local, so no new ignore is introduced.Why are the changes needed?
These ignores sit on fixable annotation gaps rather than genuine type deviations.
Removing them documents the intended contracts and lets mypy type-check the
affected code paths (for example, the streaming
partitionBylist branch waspreviously unreachable to the type checker).
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests. Verified with mypy over the full
python/pysparkscope.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8)