-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add missing type hints for tests.unittest. #13397
Changes from 1 commit
1674b7f
6c0344a
e36b12d
e4012f0
4853dd5
76270c3
5a21ef7
700dfcf
aca8cf6
603d70a
74d6acb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| import canonicaljson | ||
| import signedjson.key | ||
| import unpaddedbase64 | ||
| from typing_extensions import Protocol | ||
| from typing_extensions import ParamSpec, Protocol | ||
|
|
||
| from twisted.internet.defer import Deferred, ensureDeferred | ||
| from twisted.python.failure import Failure | ||
|
|
@@ -88,6 +88,9 @@ | |
| TV = TypeVar("TV") | ||
| _ExcType = TypeVar("_ExcType", bound=BaseException, covariant=True) | ||
|
|
||
| P = ParamSpec("P") | ||
| R = TypeVar("R") | ||
|
|
||
|
|
||
| class _TypedFailure(Generic[_ExcType], Protocol): | ||
| """Extension to twisted.Failure, where the 'value' has a certain type.""" | ||
|
|
@@ -97,7 +100,7 @@ def value(self) -> _ExcType: | |
| ... | ||
|
|
||
|
|
||
| def around(target): | ||
| def around(target: TV) -> Callable[[Callable[P, R]], None]: | ||
| """A CLOS-style 'around' modifier, which wraps the original method of the | ||
| given instance with another piece of code. | ||
|
|
||
|
|
@@ -106,11 +109,11 @@ def method_name(orig, *args, **kwargs): | |
| return orig(*args, **kwargs) | ||
| """ | ||
|
|
||
| def _around(code): | ||
| def _around(code: Callable[P, R]) -> None: | ||
| name = code.__name__ | ||
| orig = getattr(target, name) | ||
|
|
||
clokep marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def new(*args, **kwargs): | ||
| def new(*args: P.args, **kwargs: P.kwargs) -> R: | ||
| return code(orig, *args, **kwargs) | ||
|
|
||
| setattr(target, name, new) | ||
|
||
|
|
@@ -131,7 +134,7 @@ def __init__(self, methodName: str): | |
| level = getattr(method, "loglevel", getattr(self, "loglevel", None)) | ||
|
|
||
| @around(self) | ||
| def setUp(orig): | ||
| def setUp(orig: Callable[[], R]) -> R: | ||
| # if we're not starting in the sentinel logcontext, then to be honest | ||
| # all future bets are off. | ||
| if current_context(): | ||
|
|
@@ -144,7 +147,7 @@ def setUp(orig): | |
| if level is not None and old_level != level: | ||
|
|
||
| @around(self) | ||
| def tearDown(orig): | ||
| def tearDown(orig: Callable[[], R]) -> R: | ||
| ret = orig() | ||
| logging.getLogger().setLevel(old_level) | ||
| return ret | ||
|
|
@@ -158,7 +161,7 @@ def tearDown(orig): | |
| return orig() | ||
|
|
||
| @around(self) | ||
| def tearDown(orig): | ||
| def tearDown(orig: Callable[[], R]) -> R: | ||
| ret = orig() | ||
| # force a GC to workaround problems with deferreds leaking logcontexts when | ||
| # they are GCed (see the logcontext docs) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.