[python-package] Replace bare Any with specific types in sklearn helpers#12111
Open
PavelGuzenfeld wants to merge 2 commits intodmlc:masterfrom
Open
[python-package] Replace bare Any with specific types in sklearn helpers#12111PavelGuzenfeld wants to merge 2 commits intodmlc:masterfrom
PavelGuzenfeld wants to merge 2 commits intodmlc:masterfrom
Conversation
Replace generic Any annotations with ArrayLike for data parameters and DMatrix for return types in internal helper functions: - _wrap_evaluation_matrices: 13 params Any -> ArrayLike, return Tuple[Any, ...] -> Tuple[DMatrix, List[Tuple[DMatrix, str]]] - pick_ref_categories: X param Any -> ArrayLike - invalid_type: m param Any -> object Remaining Any usages (**kwargs, Dict[str, Any] for params) are intentional as they represent genuinely heterogeneous data. Follow-up to dmlc#6496.
PavelGuzenfeld
added a commit
to PavelGuzenfeld/xgboost
that referenced
this pull request
Mar 19, 2026
trivialfis
reviewed
Mar 20, 2026
| return wrapped | ||
|
|
||
| def invalid_type(m: Any) -> None: | ||
| def invalid_type(m: object) -> None: |
Contributor
Author
There was a problem hiding this comment.
object is the proper top type in Python — it means "accepts anything" while keeping type safety. Any disables type checking entirely (both co- and contra-variant), so mypy silently skips any misuse. Since invalid_type only calls type(m), which works on every object, object is the accurate annotation.
That said, this is a minor stylistic point — happy to revert if you prefer keeping Any here.
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.
Summary
Replace generic
Anyannotations with more descriptive types in sklearn.py internal helper functions. Follow-up to #6496.Changes:
_wrap_evaluation_matricesX,yAnyArrayLike_wrap_evaluation_matricesgroup,qid,sample_weight,base_marginOptional[Any]Optional[ArrayLike]_wrap_evaluation_matriceseval_setOptional[Sequence[Tuple[Any, Any]]]Optional[Sequence[Tuple[ArrayLike, ArrayLike]]]_wrap_evaluation_matrices*_eval_set,eval_group,eval_qidOptional[Sequence[Any]]Optional[Sequence[ArrayLike]]pick_ref_categoriesXAnyArrayLikeinvalid_typemAnyobjectThe return type of
_wrap_evaluation_matricesstaysTuple[Any, ...]since it is called with bothDMatrixandDaskDMatrix(which does not extendDMatrix).Remaining
Anyusages (**kwargs: Any,Dict[str, Any]for params) are intentional — they represent genuinely heterogeneous data or standard sklearn patterns.Test plan