Skip to content

Commit b4b8165

Browse files
gaogaotiantianHyukjinKwon
authored andcommitted
[SPARK-55355][PYTHON] Upgrade mypy version to the latest
### What changes were proposed in this pull request? Upgrade mypy version to 1.19.1. Fix all the type hint errors after version upgrade. ### Why are the changes needed? mypy version is out of date. The latest mypy infers type better (so we removed a lot of type ignores). We should try to keep mypy version as new as possible. We will come up with a plan to upgrade it without too much pain. ### Does this PR introduce _any_ user-facing change? It should not. ### How was this patch tested? CI. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #54132 from gaogaotiantian/upgrade-mypy. Authored-by: Tian Gao <gaogaotiantian@hotmail.com> Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
1 parent 378e74a commit b4b8165

File tree

39 files changed

+102
-121
lines changed

39 files changed

+102
-121
lines changed

dev/create-release/spark-rm/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ RUN python3.10 -m pip install --ignore-installed 'blinker>=1.6.2' && \
6060
RUN python3.10 -m pip install 'sphinx==4.5.0' mkdocs 'pydata_sphinx_theme>=0.13' \
6161
sphinx-copybutton nbsphinx numpydoc jinja2 markupsafe 'pyzmq<24.0.0' \
6262
ipython ipython_genutils sphinx_plotly_directive 'numpy>=1.22' pyarrow pandas \
63-
'plotly>=4.8' 'docutils<0.18.0' 'flake8==3.9.0' 'mypy==1.8.0' 'pytest==7.1.3' \
63+
'plotly>=4.8' 'docutils<0.18.0' 'flake8==3.9.0' 'mypy==1.19.1' 'pytest==7.1.3' \
6464
'pytest-mypy-plugins==1.9.3' 'black==23.12.1' 'pandas-stubs==1.2.0.53' \
6565
'grpcio==1.76.0' 'grpc-stubs==1.24.11' 'googleapis-common-protos-stubs==2.2.0' \
6666
'sphinxcontrib-applehelp==1.0.4' 'sphinxcontrib-devhelp==1.0.2' \

dev/lint-python

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FLAKE8_BUILD="flake8"
2020
MINIMUM_FLAKE8="3.9.0"
2121
RUFF_BUILD="ruff"
2222
MINIMUM_RUFF="0.14.0"
23-
MINIMUM_MYPY="1.8.0"
23+
MINIMUM_MYPY="1.19.1"
2424
MYPY_BUILD="mypy"
2525
PYTEST_BUILD="pytest"
2626

dev/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ tabulate
2424

2525
# Linter
2626
ruff==0.14.8
27-
mypy==1.8.0
28-
pytest-mypy-plugins==1.9.3
27+
mypy==1.19.1
28+
pytest-mypy-plugins==3.2.0
2929
# See SPARK-38680.
3030
pandas-stubs>=2.2.0
3131
scipy-stubs;

dev/spark-test-image/docs/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python3.11
9494
# See 'docutils<0.18.0' in SPARK-39421
9595
RUN python3.11 -m pip install 'sphinx==4.5.0' mkdocs 'pydata_sphinx_theme>=0.13' sphinx-copybutton nbsphinx numpydoc jinja2 markupsafe 'pyzmq<24.0.0' \
9696
ipython ipython_genutils sphinx_plotly_directive 'numpy>=1.22' pyarrow 'pandas==2.3.3' 'plotly>=4.8' 'docutils<0.18.0' \
97-
'flake8==3.9.0' 'mypy==1.8.0' 'pytest==7.1.3' 'pytest-mypy-plugins==1.9.3' 'black==23.12.1' \
97+
'flake8==3.9.0' 'mypy==1.19.1' 'pytest==7.1.3' 'pytest-mypy-plugins==1.9.3' 'black==23.12.1' \
9898
'pandas-stubs==1.2.0.53' 'grpcio==1.76.0' 'grpcio-status==1.76.0' 'protobuf==6.33.5' 'grpc-stubs==1.24.11' 'googleapis-common-protos-stubs==2.2.0' \
9999
'sphinxcontrib-applehelp==1.0.4' 'sphinxcontrib-devhelp==1.0.2' 'sphinxcontrib-htmlhelp==2.0.1' 'sphinxcontrib-qthelp==1.0.3' 'sphinxcontrib-serializinghtml==1.1.5' \
100100
&& python3.11 -m pip cache purge

dev/spark-test-image/lint/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ RUN python3.12 -m pip install \
8989
'ipython_genutils' \
9090
'jinja2' \
9191
'matplotlib' \
92-
'mypy==1.8.0' \
92+
'mypy==1.19.1' \
9393
'numpy==2.4.1' \
9494
'numpydoc' \
9595
'pandas' \

examples/src/main/python/ml/pipeline_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
rid, text, prob, prediction = row
6666
print(
6767
"(%d, %s) --> prob=%s, prediction=%f" % (
68-
rid, text, str(prob), prediction # type: ignore
68+
rid, text, str(prob), prediction
6969
)
7070
)
7171
# $example off$

python/pyspark/core/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,8 @@ def parallelize(self, c: Iterable[T], numSlices: Optional[int] = None) -> RDD[T]
836836
size = len(c)
837837
if size == 0:
838838
return self.parallelize([], numSlices)
839-
step = c[1] - c[0] if size > 1 else 1 # type: ignore[index]
840-
start0 = c[0] # type: ignore[index]
839+
step = c[1] - c[0] if size > 1 else 1
840+
start0 = c[0]
841841

842842
def getStart(split: int) -> int:
843843
assert numSlices is not None

python/pyspark/core/rdd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1664,7 +1664,7 @@ def func(it: Iterable[T]) -> Iterable[Any]:
16641664
# a generator, so it could return an iterator that we need to
16651665
# go through. We check the common case first, then deal with
16661666
# the undocumented behavior.
1667-
r = f(it)
1667+
r = f(it) # type: ignore[func-returns-value]
16681668
if r is None:
16691669
return iter([])
16701670
try:

python/pyspark/errors/exceptions/connect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def _convert_exception(
150150
sql_state=sql_state,
151151
server_stacktrace=stacktrace,
152152
display_server_stacktrace=display_server_stacktrace,
153-
contexts=contexts,
153+
contexts=contexts, # type: ignore[arg-type]
154154
grpc_status_code=grpc_status_code,
155155
breaking_change_info=breaking_change_info,
156156
)
@@ -164,7 +164,7 @@ def _convert_exception(
164164
sql_state=sql_state,
165165
server_stacktrace=stacktrace,
166166
display_server_stacktrace=display_server_stacktrace,
167-
contexts=contexts,
167+
contexts=contexts, # type: ignore[arg-type]
168168
grpc_status_code=grpc_status_code,
169169
breaking_change_info=breaking_change_info,
170170
)

python/pyspark/ml/classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2253,7 +2253,7 @@ def setMinWeightFractionPerNode(self, value: float) -> "RandomForestClassifier":
22532253
return self._set(minWeightFractionPerNode=value)
22542254

22552255

2256-
class RandomForestClassificationModel(
2256+
class RandomForestClassificationModel( # type: ignore[misc]
22572257
_TreeEnsembleModel,
22582258
_JavaProbabilisticClassificationModel[Vector],
22592259
_RandomForestClassifierParams,

0 commit comments

Comments
 (0)