Skip to content

TYP: add RandomState alias #38860

Closed
@erfannariman

Description

@erfannariman

This is a follow up of #38594. When adding type hints to the sample method, I ran into some problems for random_state. The reason is that numpy < 1.17.0 does not have the random.Generator class implemented. I tried to solve this with checking the numpy version with:

if np_version_under1p17:
    RandomState = Union[int, ArrayLike, np.random.RandomState]
else:
    RandomState = Union[int, ArrayLike, np.random.Generator, np.random.RandomState]

But this resulted in:

Cannot assign multiple types to name "RandomState" without an explicit "Type[...]" annotation [misc]

To solve this issue we have to add typing for random_state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Typingtype annotations, mypy/pyright type checking

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions