Skip to content

[SPARK-58410][PYTHON] Remove unnecessary type: ignore comments in the DataFrame read/write API - #57611

Open
Spenserrrr wants to merge 1 commit into
apache:masterfrom
Spenserrrr:typeignore3
Open

[SPARK-58410][PYTHON] Remove unnecessary type: ignore comments in the DataFrame read/write API#57611
Spenserrrr wants to merge 1 commit into
apache:masterfrom
Spenserrrr:typeignore3

Conversation

@Spenserrrr

@Spenserrrr Spenserrrr commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR removes 7 unnecessary # 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) — the mixin calls self.option(...) without declaring that its host provides it, requiring a # type: ignore[attr-defined]. A small SupportsOption Protocol is added and self is annotated with it, so the call type-checks and the contract is explicit. (The sibling self.schema(...) call keeps its ignore on purpose: schema is a reader-only method, but _set_opts is shared with writers, so requiring schema on self would break the writer call sites.)

  2. DataFrameReader.load (Connect) — a paths local was assigned from the wide Optional[Union[str, List[str]]] parameter and then reused across an isinstance narrowing, so mypy kept the wide first-assignment type and needed a # type: ignore[arg-type]. Declaring paths: Optional[List[str]] up front and normalizing the input removes the ignore and makes the None/str/list cases explicit.

  3. DataStreamWriter.partitionBy / clusterBy (classic + Connect) — the overload implementation signatures were *cols: str, which contradicts the List[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-streaming DataFrameWriter), and the columns are normalized into a correctly typed Sequence[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 partitionBy list branch was
previously 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/pyspark scope.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 4.8)

@Spenserrrr

Copy link
Copy Markdown
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant