Repository: scipy/scipy
File: scipy/stats/_resampling.py (Python)

Code before:

            As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
            transition from use of `numpy.random.RandomState` to
            `numpy.random.Generator`, this attribute name was changed from
            `random_state` to `rng`. For an interim period, both names will continue to
            work, although only one may be specified at a time. After the interim
            period, uses of `random_state` will emit warnings. The behavior of both
            `random_state` and `rng` are outlined above, but only `rng` should be used
            in new code.

    """
    rng: int
    _rng: int = field(init=False, repr=False, default=9999)

    @property
    def random_state(self):
        # warnings.warn(_rs_deprecation, DeprecationWarning, level=2)
        return self._rng

    @random_state.setter
    def random_state(self, val):
        # warnings.warn(_rs_deprecation, DeprecationWarning, level=2)
        self._rng = val

    @property
    def rng(self):
        return self._rng

    @random_state.setter
    def rng(self, val):
        self._rng = np.random.default_rng(val)

    @_transition_to_rng('random_state', position_num=3, replace_doc=False)
    def __init__(self, n_resamples=9999, batch=None, rng=None):
        self._rng = rng  # don't validate with `default_rng` during SPEC 7 transition
        super().__init__(n_resamples=n_resamples, batch=batch)

    def _asdict(self):
        # `dataclasses.asdict` deepcopies; we don't want that.
        return dict(n_resamples=self.n_resamples, batch=self.batch, rng=self.rng)


@dataclass
class BootstrapMethod(ResamplingMethod):
    """Configuration information for a bootstrap confidence interval.

    Instances of this class can be passed into the `method` parameter of some
    confidence interval methods to generate a bootstrap confidence interval.

    Attributes
    ----------

Review comment (suggestion):
```suggestion
    def rng(self):  # type: ignore[no-redef]  # noqa: F811
```

Code after:

        .. versionchanged:: 1.15.0

            As part of the `SPEC-007 <https://scientific-python.org/specs/spec-0007/>`_
            transition from use of `numpy.random.RandomState` to
            `numpy.random.Generator`, this attribute name was changed from
            `random_state` to `rng`. For an interim period, both names will continue to
            work, although only one may be specified at a time. After the interim
            period, uses of `random_state` will emit warnings. The behavior of both
            `random_state` and `rng` are outlined above, but only `rng` should be used
            in new code.

    """
    rng: object  # type: ignore[misc]
    _rng: object = field(init=False, repr=False, default=None)  # type: ignore[assignment]

    @property
    def random_state(self):
        # Uncomment in SciPy 1.17.0
        # warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
        return self._rng

    @random_state.setter
    def random_state(self, val):
        # Uncomment in SciPy 1.17.0
        # warnings.warn(_rs_deprecation, DeprecationWarning, stacklevel=2)
        self._rng = val

    @property  # type: ignore[no-redef]
    def rng(self):  # noqa: F811
        return self._rng

    @random_state.setter
    def rng(self, val):  # noqa: F811
        self._rng = np.random.default_rng(val)

    @_transition_to_rng('random_state', position_num=3, replace_doc=False)
    def __init__(self, n_resamples=9999, batch=None, rng=None):
        self._rng = rng  # don't validate with `default_rng` during SPEC 7 transition
        super().__init__(n_resamples=n_resamples, batch=batch)

    def _asdict(self):
        # `dataclasses.asdict` deepcopies; we don't want that.
        return dict(n_resamples=self.n_resamples, batch=self.batch, rng=self.rng)


@dataclass
class BootstrapMethod(ResamplingMethod):
    """Configuration information for a bootstrap confidence interval.

    Instances of this class can be passed into the `method` parameter of some