8000 Merge pull request #935 from rafsaf/gauge_typing_improve · hugovk/client_python@3724a8a · GitHub
[go: up one dir, main page]

Skip to content

Commit 3724a8a

Browse files
authored
Merge pull request prometheus#935 from rafsaf/gauge_typing_improve
Gauge typing improvement
2 parents 3a826dc + 3b49279 commit 3724a8a

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

prometheus_client/context_managers.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import sys
21
from timeit import default_timer
32
from types import TracebackType
43
from typing import (
5-
Any, Callable, Optional, Tuple, Type, TYPE_CHECKING, TypeVar, Union,
4+
Any, Callable, Literal, Optional, Tuple, Type, TYPE_CHECKING, TypeVar,
5+
Union,
66
)
77

8-
if sys.version_info >= (3, 8, 0):
9-
from typing import Literal
10-
118
from .decorator import decorate
129

1310
if TYPE_CHECKING:
@@ -23,7 +20,7 @@ def __init__(self, counter: "Counter", exception: Union[Type[BaseException], Tup
2320
def __enter__(self) -> None:
2421
pass
2522

26-
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> "Literal[False]":
23+
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> Literal[False]:
2724
if isinstance(value, self._exception):
2825
self._counter.inc()
2926
return False

prometheus_client/exposition.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
CONTENT_TYPE_LATEST = 'text/plain; version=0.0.4; charset=utf-8'
4040
"""Content type of the latest text format"""
41-
PYTHON376_OR_NEWER = sys.version_info > (3, 7, 5)
4241

4342

4443
class _PrometheusRedirectHandler(HTTPRedirectHandler):
@@ -545,10 +544,7 @@ def _use_gateway(
545544
) -> None:
546545
gateway_url = urlparse(gateway)
547546
# See https://bugs.python.org/issue27657 for details on urlparse in py>=3.7.6.
548-
if not gateway_url.scheme or (
549-
PYTHON376_OR_NEWER
550-
and gateway_url.scheme not in ['http', 'https']
551-
):
547+
if not gateway_url.scheme or gateway_url.scheme not in ['http', 'https']:
552548
gateway = f'http://{gateway}'
553549

554550
gateway = gateway.rstrip('/')

prometheus_client/metrics.py

B669 Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import time
44
import types
55
from typing import (
6-
Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type,
7-
TypeVar, Union,
6+
Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple,
7+
Type, TypeVar, Union,
88
)
99

1010
from . import values # retain this import style for testability
@@ -357,7 +357,7 @@ def __init__(self,
357357
unit: str = '',
358358
registry: Optional[CollectorRegistry] = REGISTRY,
359359
_labelvalues: Optional[Sequence[str]] = None,
360-
multiprocess_mode: str = 'all',
360+
multiprocess_mode: Literal['all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum'] = 'all',
361361
):
362362
self._multiprocess_mode = multiprocess_mode
363363
if multiprocess_mode not in self._MULTIPROC_MODES:

0 commit comments

Comments
 (0)
0