From ebcfe7bc4e5a02732db130c96e985e9a33373a6b Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Tue, 1 Mar 2022 00:27:44 -0800 Subject: [PATCH] random: use bound methods (#7408) --- stdlib/random.pyi | 74 ++++++++++-------------------- tests/stubtest_allowlists/py36.txt | 1 - tests/stubtest_allowlists/py37.txt | 1 - tests/stubtest_allowlists/py38.txt | 1 - 4 files changed, 25 insertions(+), 52 deletions(-) diff --git a/stdlib/random.pyi b/stdlib/random.pyi index b031ade0b..16aa31a0f 100644 --- a/stdlib/random.pyi +++ b/stdlib/random.pyi @@ -122,53 +122,29 @@ class SystemRandom(Random): def setstate(self, *args: Any, **kwds: Any) -> NoReturn: ... # ----- random function stubs ----- + +_inst: Random = ... +seed = _inst.seed +random = _inst.random +uniform = _inst.uniform +triangular = _inst.triangular +randint = _inst.randint +choice = _inst.choice +randrange = _inst.randrange +sample = _inst.sample +shuffle = _inst.shuffle +choices = _inst.choices +normalvariate = _inst.normalvariate +lognormvariate = _inst.lognormvariate +expovariate = _inst.expovariate +vonmisesvariate = _inst.vonmisesvariate +gammavariate = _inst.gammavariate +gauss = _inst.gauss +betavariate = _inst.betavariate +paretovariate = _inst.paretovariate +weibullvariate = _inst.weibullvariate +getstate = _inst.getstate +setstate = _inst.setstate +getrandbits = _inst.getrandbits if sys.version_info >= (3, 9): - def seed(a: int | float | str | bytes | bytearray | None = ..., version: int = ...) -> None: ... - -else: - def seed(a: Any = ..., version: int = ...) -> None: ... - -def getstate() -> object: ... -def setstate(state: object) -> None: ... -def getrandbits(__k: int) -> int: ... -def randrange(start: int, stop: None | int = ..., step: int = ...) -> int: ... -def randint(a: int, b: int) -> int: ... - -if sys.version_info >= (3, 9): - def randbytes(n: int) -> bytes: ... - -def choice(seq: SupportsLenAndGetItem[_T]) -> _T: ... -def choices( - population: SupportsLenAndGetItem[_T], - weights: Sequence[float] | None = ..., - *, - cum_weights: Sequence[float] | None = ..., - k: int = ..., -) -> list[_T]: ... -def shuffle(x: MutableSequence[Any], random: Callable[[], float] | None = ...) -> None: ... - -if sys.version_info >= (3, 9): - def sample(population: Sequence[_T] | AbstractSet[_T], k: int, *, counts: Iterable[_T] | None = ...) -> list[_T]: ... - -else: - def sample(population: Sequence[_T] | AbstractSet[_T], k: int) -> list[_T]: ... - -def random() -> float: ... -def uniform(a: float, b: float) -> float: ... -def triangular(low: float = ..., high: float = ..., mode: float | None = ...) -> float: ... -def betavariate(alpha: float, beta: float) -> float: ... -def expovariate(lambd: float) -> float: ... -def gammavariate(alpha: float, beta: float) -> float: ... - -if sys.version_info >= (3, 11): - def gauss(mu: float = ..., sigma: float = ...) -> float: ... - def normalvariate(mu: float = ..., sigma: float = ...) -> float: ... - -else: - def gauss(mu: float, sigma: float) -> float: ... - def normalvariate(mu: float, sigma: float) -> float: ... - -def lognormvariate(mu: float, sigma: float) -> float: ... -def vonmisesvariate(mu: float, kappa: float) -> float: ... -def paretovariate(alpha: float) -> float: ... -def weibullvariate(alpha: float, beta: float) -> float: ... + randbytes = _inst.randbytes diff --git a/tests/stubtest_allowlists/py36.txt b/tests/stubtest_allowlists/py36.txt index 57777448a..94025b954 100644 --- a/tests/stubtest_allowlists/py36.txt +++ b/tests/stubtest_allowlists/py36.txt @@ -34,7 +34,6 @@ mmap.ACCESS_DEFAULT (os|posix).utime pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args random.Random.randrange # missing undocumented arg _int -random.randrange # missing undocumented arg _int sched.Event.__doc__ # __slots__ is overridden stringprep.unicodedata # re-exported from unicodedata sre_compile.dis diff --git a/tests/stubtest_allowlists/py37.txt b/tests/stubtest_allowlists/py37.txt index d6495f3af..987623d79 100644 --- a/tests/stubtest_allowlists/py37.txt +++ b/tests/stubtest_allowlists/py37.txt @@ -34,7 +34,6 @@ json.loads pyexpat.XMLParserType.ExternalEntityParserCreate # C signature is wrong - function gets only positional args queue.SimpleQueue.__init__ # Default C __init__ signature is wrong random.Random.randrange # missing undocumented arg _int -random.randrange # missing undocumented arg _int re.Pattern.scanner # Undocumented and not useful. #6405 sched.Event.__doc__ # __slots__ is overridden ssl.PROTOCOL_SSLv3 # Depends on ssl compilation diff --git a/tests/stubtest_allowlists/py38.txt b/tests/stubtest_allowlists/py38.txt index a9f9fd8ae..13a72397c 100644 --- a/tests/stubtest_allowlists/py38.txt +++ b/tests/stubtest_allowlists/py38.txt @@ -47,7 +47,6 @@ multiprocessing.spawn._main pickle.Pickler.reducer_override # implemented in C pickler queue.SimpleQueue.__init__ # Default C __init__ signature is wrong random.Random.randrange # missing undocumented arg _int -random.randrange # missing undocumented arg _int re.Pattern.scanner # Undocumented and not useful. #6405 sched.Event.__doc__ # __slots__ is overridden ssl.PROTOCOL_SSLv3 # Depends on ssl compilation