Skip to content

Commit a90573f

Browse files
tornado: add some types, set version (#5742)
1 parent 80591d9 commit a90573f

File tree

2 files changed

+41
-31
lines changed

2 files changed

+41
-31
lines changed
Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
1-
from typing import Any, Optional
1+
from types import TracebackType
2+
from typing import Any, Optional, Type
3+
4+
from .concurrent import Future
25

36
class _TimeoutGarbageCollector:
4-
def __init__(self): ...
7+
def __init__(self) -> None: ...
58

69
class Condition(_TimeoutGarbageCollector):
710
io_loop: Any
8-
def __init__(self): ...
9-
def wait(self, timeout: Optional[Any] = ...): ...
10-
def notify(self, n: int = ...): ...
11-
def notify_all(self): ...
11+
def __init__(self) -> None: ...
12+
def wait(self, timeout: Optional[float] = ...) -> Future: ...
13+
def notify(self, n: int = ...) -> None: ...
14+
def notify_all(self) -> None: ...
1215

1316
class Event:
14-
def __init__(self): ...
15-
def is_set(self): ...
16-
def set(self): ...
17-
def clear(self): ...
17+
def __init__(self) -> None: ...
18+
def is_set(self) -> bool: ...
19+
def set(self) -> None: ...
20+
def clear(self) -> None: ...
1821
def wait(self, timeout: Optional[Any] = ...): ...
1922

2023
class _ReleasingContextManager:
21-
def __init__(self, obj): ...
22-
def __enter__(self): ...
24+
def __init__(self, obj) -> None: ...
25+
def __enter__(self) -> None: ...
2326
def __exit__(self, exc_type, exc_val, exc_tb): ...
2427

2528
class Semaphore(_TimeoutGarbageCollector):
26-
def __init__(self, value: int = ...): ...
27-
def release(self): ...
28-
def acquire(self, timeout: Optional[Any] = ...): ...
29-
def __enter__(self): ...
30-
__exit__: Any
31-
def __aenter__(self): ...
32-
def __aexit__(self, typ, value, tb): ...
33-
34-
class BoundedSemaphore(Semaphore):
35-
def __init__(self, value: int = ...): ...
36-
def release(self): ...
29+
def __init__(self, value: int = ...) -> None: ...
30+
def release(self) -> None: ...
31+
def acquire(self, timeout: Optional[float] = ...) -> Future: ...
32+
# __enter__ and __exit__ exist but always throw an error, so we
33+
# omit them to give better error message while type checking.
34+
def __aenter__(self) -> Future: ...
35+
def __aexit__(
36+
self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]
37+
) -> Future: ...
38+
39+
class BoundedSemaphore(Semaphore): ...
3740

3841
class Lock:
39-
def __init__(self): ...
40-
def acquire(self, timeout: Optional[Any] = ...): ...
41-
def release(self): ...
42-
def __enter__(self): ...
43-
__exit__: Any
44-
def __aenter__(self): ...
45-
def __aexit__(self, typ, value, tb): ...
42+
def __init__(self) -> None: ...
43+
def acquire(self, timeout: Optional[float] = ...) -> Future: ...
44+
def release(self) -> None: ...
45+
# __enter__ and __exit__ exist but always throw an error, so we
46+
# omit them to give better error message while type checking.
47+
def __aenter__(self) -> Future: ...
48+
def __aexit__(
49+
self, typ: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]
50+
) -> Future: ...

stubs/tornado/METADATA.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
version = "0.1"
1+
# tornado ships with types as of version 6, but
2+
# we keep these stubs around for the benefit of
3+
# Python 2 users (see #4412). Therefore, these
4+
# stubs target version 5.1, the last to support
5+
# Python 2.
6+
version = "5.1"
27
python2 = true

0 commit comments

Comments
 (0)