diff options
| author | shadchin <[email protected]> | 2022-02-10 16:44:30 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:44:30 +0300 |
| commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
| tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py | |
| parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py')
| -rw-r--r-- | contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py index 2b20d69b425..2c8deb935fb 100644 --- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py +++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/eventloop/dummy_contextvars.py @@ -1,49 +1,49 @@ -""" -Dummy contextvars implementation, to make prompt_toolkit work on Python 3.6. - -As long as there is only one application running at a time, we don't need the -real contextvars. So, stuff like the telnet-server and so on requires 3.7. -""" -from typing import Any, Callable, Generic, Optional, TypeVar - - -def copy_context() -> "Context": - return Context() - - -_T = TypeVar("_T") - - -class Context: - def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: - return callable(*args, **kwargs) - - def copy(self) -> "Context": - return self - - -class Token(Generic[_T]): - pass - - -class ContextVar(Generic[_T]): - def __init__(self, name: str, *, default: Optional[_T] = None) -> None: - self._name = name - self._value = default - - @property - def name(self) -> str: - return self._name - - def get(self, default: Optional[_T] = None) -> _T: - result = self._value or default - if result is None: - raise LookupError - return result - - def set(self, value: _T) -> Token[_T]: - self._value = value - return Token() - - def reset(self, token: Token[_T]) -> None: - pass +""" +Dummy contextvars implementation, to make prompt_toolkit work on Python 3.6. + +As long as there is only one application running at a time, we don't need the +real contextvars. So, stuff like the telnet-server and so on requires 3.7. +""" +from typing import Any, Callable, Generic, Optional, TypeVar + + +def copy_context() -> "Context": + return Context() + + +_T = TypeVar("_T") + + +class Context: + def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: + return callable(*args, **kwargs) + + def copy(self) -> "Context": + return self + + +class Token(Generic[_T]): + pass + + +class ContextVar(Generic[_T]): + def __init__(self, name: str, *, default: Optional[_T] = None) -> None: + self._name = name + self._value = default + + @property + def name(self) -> str: + return self._name + + def get(self, default: Optional[_T] = None) -> _T: + result = self._value or default + if result is None: + raise LookupError + return result + + def set(self, value: _T) -> Token[_T]: + self._value = value + return Token() + + def reset(self, token: Token[_T]) -> None: + pass |
