bearomorphism opened a new pull request, #59388:
URL: https://github.com/apache/spark/pull/59388
### What changes were proposed in this pull request?
- Explicitly declare `SparkContext._accumulatorServer` as an optional union
of the TCP and Unix-domain accumulator server types, with a default of `None`.
- Replace the `getattr` guard in `stop()` with a direct `is not None` check.
- Remove the assignment type ignore when resetting the member to `None`
after shutdown.
### Why are the changes needed?
The inferred type only accounts for the running server, but `stop()` resets
the member to `None`. The explicit annotation reflects this lifecycle. The
default also makes direct access safe when initialization fails before creating
the server, eliminating the need for `getattr`.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
The following checks passed locally using Python 3.13.5, mypy 1.19.1, and
Ruff 0.14.8. The environment uses the CI-pinned pandas and pandas-stubs
versions from `pyproject.toml`.
```bash
source .venv/bin/activate
mypy --config-file python/mypy.ini python/pyspark/core/context.py
ruff check python/pyspark/core/context.py
ruff format --check python/pyspark/core/context.py
SPARK_LOCAL_IP=localhost python/run-tests \
--python-executables="$PWD/.venv/bin/python" \
--parallelism=1 \
--testnames 'pyspark.tests.test_context
ContextTests.test_failed_sparkcontext_creation ContextTests.test_stop
ContextTests.test_with_stop ContextTests.test_with_exception'
git diff --check
```
No new tests were added because the existing targeted tests cover
initialization failure, shutdown, repeated shutdown, and exception cleanup.
This change corrects the private member's annotation and simplifies the
existing guard.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: pi 1.1.0 with OpenAI gpt-6-astra
--
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]