diff --git a/prometheus_client/context_managers.py b/prometheus_client/context_managers.py index 964a9304..3988ec22 100644 --- a/prometheus_client/context_managers.py +++ b/prometheus_client/context_managers.py @@ -1,13 +1,10 @@ -import sys from timeit import default_timer from types import TracebackType from typing import ( - Any, Callable, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, Union, + Any, Callable, Literal, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, + Union, ) -if sys.version_info >= (3, 8, 0): - from typing import Literal - from .decorator import decorate if TYPE_CHECKING: @@ -23,7 +20,7 @@ def __init__(self, counter: "Counter", exception: Union[Type[BaseException], Tup def __enter__(self) -> None: pass - def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> "Literal[False]": + def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> Literal[False]: if isinstance(value, self._exception): self._counter.inc() return False diff --git a/prometheus_client/exposition.py b/prometheus_client/exposition.py index deaa6ed5..13af927b 100644 --- a/prometheus_client/exposition.py +++ b/prometheus_client/exposition.py @@ -38,7 +38,6 @@ CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8' """Content type of the latest text format""" -PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5) class _PrometheusRedirectHandler(HTTPRedirectHandler): @@ -545,10 +544,7 @@ def _use_gateway( ) -> None: gateway_url = urlparse(gateway) # See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6. - if not gateway_url.scheme or ( - PYTHON376_OR_NEWER - and gateway_url.scheme not in ['http', 'https'] - ): + if not gateway_url.scheme or gateway_url.scheme not in ['http', 'https']: gateway = f'http://{gateway}' gateway = gateway.rstrip('/') diff --git a/prometheus_client/metrics.py b/prometheus_client/metrics.py index 392e1e4d..66f51fa6 100644 --- a/prometheus_client/metrics.py +++ b/prometheus_client/metrics.py @@ -3,8 +3,8 @@ import time import types from typing import ( - Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type, - TypeVar, Union, + Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple, + Type, TypeVar, Union, ) from . import values # retain this import style for testability @@ -357,7 +357,7 @@ def __init__(self, unit: str = '', registry: Optional[CollectorRegistry] = REGISTRY, _labelvalues: Optional[Sequence[str]] = None, - multiprocess_mode: str = 'all', + multiprocess_mode: Literal['all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum'] = 'all', ): self._multiprocess_mode = multiprocess_mode if multiprocess_mode not in self._MULTIPROC_MODES: