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

Code before:
        may have been defined symbolically, or through a callable.
    contains(item, parameter_values)
        (Inherited) Determines whether the argument is contained within the
        domain
    __str__()
        Returns a string representation of the domain, e.g. "[a, b)".
    draw(size, rng, proportions, parameter_values)
        Draws random values based on the domain. Proportions of values within
        the domain, on the endpoints of the domain, outside the domain,
        and having value NaN are specified by `proportions`.

    """
    def _get_endpoint_str(self, endpoint, funcname):
        if callable(endpoint):
            if endpoint.__doc__ is not None:
                return endpoint.__doc__
            params = inspect.signature(endpoint).parameters.values()
            params = [
                p.name for p in params if p.kind == inspect.Parameter.KEYWORD_ONLY
            ]
            return f"{funcname}({','.join(params)})"
        return self.symbols.get(endpoint, f"{endpoint}")

    def __str__(self):
        a, b = self.endpoints
        a, b = self._get_endpoint_str(a, "f1"), self._get_endpoint_str(b, "f2")
        left_inclusive, right_inclusive = self.inclusive
        left = "[" if left_inclusive else "("
        right = "]" if right_inclusive else ")"

        return f"{left}{a}, {b}{right}"

    def draw(self, n, type_, min, max, squeezed_base_shape, rng=None):
        r""" Draw random values from the domain.

        Parameters
        ----------
        n : int
            The number of values to be drawn from the domain.
        type_ : str
            A string indicating whether the values are

            - strictly within the domain ('in'),
            - at one of the two endpoints ('on'),
            - strictly outside the domain ('out'), or
            - NaN ('nan').
        min, max : ndarray
            The endpoints of the domain.
        squeezed_based_shape : tuple of ints
            See _RealParameter.draw.
        rng : np.Generator

Review comment (suggestion):
There are some tests of the `__str__` method of `_RealDomain` that maybe could be updated:
https://github.com/scipy/scipy/blob/0b91033ba51a8756de2c4b3ce4c1e6dfeb3884eb/scipy/stats/tests/test_continuous.py#L108

Could also add oddball things to
https://github.com/scipy/scipy/blob/0b91033ba51a8756de2c4b3ce4c1e6dfeb3884eb/scipy/stats/tests/test_continuous.py#L1713

if they don't fit elsewhere.

Code after:
    get_numerical_endpoints(parameter_values)
        (Inherited) Gets the numerical values of the domain endpoints, which
        may have been defined symbolically, or through a callable.
    contains(item, parameter_values)
        (Inherited) Determines whether the argument is contained within the
        domain
    __str__()
        Returns a string representation of the domain, e.g. "[a, b)".
    draw(size, rng, proportions, parameter_values)
        Draws random values based on the domain. Proportions of values within
        the domain, on the endpoints of the domain, outside the domain,
        and having value NaN are specified by `proportions`.

    """
    def _get_endpoint_str(self, endpoint, funcname):
        if callable(endpoint):
            if endpoint.__doc__ is not None:
                return endpoint.__doc__
            params = inspect.signature(endpoint).parameters.values()
            params = [
                p.name for p in params if p.kind == inspect.Parameter.KEYWORD_ONLY
            ]
            return f"{funcname}({','.join(params)})"
        return self.symbols.get(endpoint, f"{endpoint}")

    def __str__(self):
        a, b = self.endpoints
        a, b = self._get_endpoint_str(a, "f1"), self._get_endpoint_str(b, "f2")
        left_inclusive, right_inclusive = self.inclusive
        left = "[" if left_inclusive else "("
        right = "]" if right_inclusive else ")"

        return f"{left}{a}, {b}{right}"

    def draw(self, n, type_, min, max, squeezed_base_shape, rng=None):
        r""" Draw random values from the domain.

        Parameters
        ----------
        n : int
            The number of values to be drawn from the domain.
        type_ : str
            A string indicating whether the values are

            - strictly within the domain ('in'),
            - at one of the two endpoints ('on'),
            - strictly outside the domain ('out'), or
            - NaN ('nan').
        min, max : ndarray
            The endpoints of the domain.
        squeezed_based_shape : tuple of ints