Skip to content

[python-package] Add specific error codes to all type: ignore comments#12110

Merged
trivialfis merged 5 commits into
dmlc:masterfrom
PavelGuzenfeld:fix/type-ignore-error-codes
Mar 20, 2026
Merged

[python-package] Add specific error codes to all type: ignore comments#12110
trivialfis merged 5 commits into
dmlc:masterfrom
PavelGuzenfeld:fix/type-ignore-error-codes

Conversation

@PavelGuzenfeld

@PavelGuzenfeld PavelGuzenfeld commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace all 25 generic # type: ignore comments across the Python package with specific mypy error codes. This is a follow-up to #6496.

Changes across 10 files:

Error code Count Example
[union-attr] 7 TypeGuard limitations, optional attribute access, PySpark set()
[attr-defined] 6 Deprecated pandas API, numpy dtypes, ctypes CDLL, spark estimator
[no-redef] 5 Conditional class/import redefinitions (3 existing + 2 cudf)
[arg-type] 4 PySpark mapInPandas() / np.stack(), callback append()
[assignment] 2 Type narrowing, None assignment
[return-value] 1 _load_lib() returning None for doc builds
[name-defined] 1 pd.arrays.ArrowExtensionArray not in stubs
[call-overload] 1 PySpark @pandas_udf decorator
[index, typeddict-unknown-key] 1 CUDA stream on Optional[ArrayInf]

Why: Generic type: ignore silently masks any type error on that line, including new unrelated errors introduced by future changes. Specific error codes ensure only the known issue is suppressed.

No functional changes — only comment annotations.

Test plan

  • CI pre-commit passes
  • CI mypy type check passes — all error codes verified against actual mypy output

Replace all 25 generic `# type: ignore` comments with specific mypy
error codes (e.g. `[attr-defined]`, `[union-attr]`, `[assignment]`).
This prevents the ignores from silently masking unrelated type errors
introduced in future changes.

The 3 existing `[no-redef]` annotations in compat.py are unchanged.
PavelGuzenfeld added a commit to PavelGuzenfeld/xgboost that referenced this pull request Mar 19, 2026
PavelGuzenfeld and others added 4 commits March 20, 2026 00:22
Corrected error codes based on CI mypy output:
- _data_utils.py:378: typeddict-unknown-key -> index
- data.py:503: assignment -> name-defined
- data.py:981,985: import-untyped -> no-redef
- callback.py:442,445: union-attr -> arg-type
- spark/core.py:1688,1703: arg-type -> union-attr
- testing/updater.py:658: union-attr -> assignment
- _data_utils.py:378: add both [index, typeddict-unknown-key] codes
- data.py:981,985: move type: ignore to from-line for multi-line imports
@trivialfis
trivialfis merged commit 3f6d458 into dmlc:master Mar 20, 2026
78 checks passed
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.

2 participants