From c4fb92c6585f90b6a99a884c8a4859ce46d7f884 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 29 Apr 2021 13:11:58 +0200 Subject: [PATCH] Make type hints compatible with Python 3.8 --- PFERD/conductor.py | 11 ++++++----- PFERD/limiter.py | 7 ++++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/PFERD/conductor.py b/PFERD/conductor.py index bf41f61..86df7e4 100644 --- a/PFERD/conductor.py +++ b/PFERD/conductor.py @@ -1,8 +1,9 @@ import asyncio -from contextlib import (AbstractAsyncContextManager, AbstractContextManager, - asynccontextmanager, contextmanager) +from contextlib import asynccontextmanager, contextmanager from pathlib import Path -from typing import AsyncIterator, Iterator, List, Optional +# TODO If we upgrade to python 3.9, these context manager hints are deprecated +from typing import (AsyncContextManager, AsyncIterator, ContextManager, + Iterator, List, Optional) import rich from rich.markup import escape @@ -59,7 +60,7 @@ class TerminalConductor: finally: self.start() - def exclusive_output(self) -> AbstractAsyncContextManager[None]: + def exclusive_output(self) -> AsyncContextManager[None]: return self._exclusive_output_cm() @contextmanager @@ -79,5 +80,5 @@ class TerminalConductor: self, description: Path, steps: Optional[float], - ) -> AbstractContextManager[ProgressBar]: + ) -> ContextManager[ProgressBar]: return self._progress_bar_cm(escape(str(description)), steps=steps) diff --git a/PFERD/limiter.py b/PFERD/limiter.py index f73e2cd..f001d8b 100644 --- a/PFERD/limiter.py +++ b/PFERD/limiter.py @@ -1,6 +1,7 @@ import asyncio -from contextlib import AbstractAsyncContextManager, asynccontextmanager -from typing import AsyncIterator +from contextlib import asynccontextmanager +# TODO If we upgrade to python 3.9, this context manager hint is deprecated +from typing import AsyncContextManager, AsyncIterator class Limiter: @@ -15,5 +16,5 @@ class Limiter: finally: self._semaphore.release() - def limit(self) -> AbstractAsyncContextManager[None]: + def limit(self) -> AsyncContextManager[None]: return self._context_manager()