From a90573feb2af118d224d9b9baf6cb7a3e2b0c64a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 11 Jul 2021 04:17:40 -0700 Subject: [PATCH] tornado: add some types, set version (#5742) --- stubs/tornado/@python2/tornado/locks.pyi | 63 +++++++++++++----------- stubs/tornado/METADATA.toml | 7 ++- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/stubs/tornado/@python2/tornado/locks.pyi b/stubs/tornado/@python2/tornado/locks.pyi index 723e99134..8b3c99ce7 100644 --- a/stubs/tornado/@python2/tornado/locks.pyi +++ b/stubs/tornado/@python2/tornado/locks.pyi @@ -1,45 +1,50 @@ -from typing import Any, Optional +from types import TracebackType +from typing import Any, Optional, Type + +from .concurrent import Future class _TimeoutGarbageCollector: - def __init__(self): ... + def __init__(self) -> None: ... class Condition(_TimeoutGarbageCollector): io_loop: Any - def __init__(self): ... - def wait(self, timeout: Optional[Any] = ...): ... - def notify(self, n: int = ...): ... - def notify_all(self): ... + def __init__(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> Future: ... + def notify(self, n: int = ...) -> None: ... + def notify_all(self) -> None: ... class Event: - def __init__(self): ... - def is_set(self): ... - def set(self): ... - def clear(self): ... + def __init__(self) -> None: ... + def is_set(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... def wait(self, timeout: Optional[Any] = ...): ... class _ReleasingContextManager: - def __init__(self, obj): ... - def __enter__(self): ... + def __init__(self, obj) -> None: ... + def __enter__(self) -> None: ... def __exit__(self, exc_type, exc_val, exc_tb): ... class Semaphore(_TimeoutGarbageCollector): - def __init__(self, value: int = ...): ... - def release(self): ... - def acquire(self, timeout: Optional[Any] = ...): ... - def __enter__(self): ... - __exit__: Any - def __aenter__(self): ... - def __aexit__(self, typ, value, tb): ... + def __init__(self, value: int = ...) -> None: ... + def release(self) -> None: ... + def acquire(self, timeout: Optional[float] = ...) -> Future: ... + # __enter__ and __exit__ exist but always throw an error, so we + # omit them to give better error message while type checking. + def __aenter__(self) -> Future: ... + def __aexit__( + self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType] + ) -> Future: ... -class BoundedSemaphore(Semaphore): - def __init__(self, value: int = ...): ... - def release(self): ... +class BoundedSemaphore(Semaphore): ... class Lock: - def __init__(self): ... - def acquire(self, timeout: Optional[Any] = ...): ... - def release(self): ... - def __enter__(self): ... - __exit__: Any - def __aenter__(self): ... - def __aexit__(self, typ, value, tb): ... + def __init__(self) -> None: ... + def acquire(self, timeout: Optional[float] = ...) -> Future: ... + def release(self) -> None: ... + # __enter__ and __exit__ exist but always throw an error, so we + # omit them to give better error message while type checking. + def __aenter__(self) -> Future: ... + def __aexit__( + self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType] + ) -> Future: ... diff --git a/stubs/tornado/METADATA.toml b/stubs/tornado/METADATA.toml index 31f638bf3..542cb2dc9 100644 --- a/stubs/tornado/METADATA.toml +++ b/stubs/tornado/METADATA.toml @@ -1,2 +1,7 @@ -version = "0.1" +# tornado ships with types as of version 6, but +# we keep these stubs around for the benefit of +# Python 2 users (see #4412). Therefore, these +# stubs target version 5.1, the last to support +# Python 2. +version = "5.1" python2 = true