8000 Fix typing build errors · reinaldoca/client_python@7c44be2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c44be2

Browse files
committed
Fix typing build errors
CI must not have run properly on the typing PR and there are several build/lint errors. Generally add spaces around = when types are used, and only import Literal if using Python 3.8 or later. Signed-off-by: Chris Marchbanks <csmarchbanks@gmail.com>
1 parent 822b8e9 commit 7c44be2

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

prometheus_client/context_managers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import sys
12
from timeit import default_timer
< 8000 code>23
from types import TracebackType
3-
from typing import (
4-
Any, Callable, Literal, Optional, Type, TYPE_CHECKING, TypeVar,
5-
)
4+
from typing import Any, Callable, Optional, Type, TYPE_CHECKING, TypeVar
5+
6+
if sys.version_info >= (3, 8, 0):
7+
from typing import Literal
68

79
from .decorator import decorate
810

@@ -19,7 +21,7 @@ def __init__(self, counter: "Counter", exception: Type[BaseException]) -> None:
1921
def __enter__(self) -> None:
2022
pass
2123

22-
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> Literal[False]:
24+
def __exit__(self, typ: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]) -> "Literal[False]":
2325
if isinstance(value, self._exception):
2426
self._counter.inc()
2527
return False

prometheus_client/metrics.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ def __repr__(self):
103103
def __init__(self: T,
104104
name: str,
105105
documentation: str,
106-
labelnames: Sequence[str]=(),
107-
namespace: str='',
108-
subsystem: str='',
109-
unit: str='',
110-
registry: CollectorRegistry=REGISTRY,
111-
_labelvalues: Optional[Sequence[str]]=None,
106+
labelnames: Sequence[str] = (),
107+
namespace: str = '',
108+
subsystem: str = '',
109+
unit: str = '',
110+
registry: CollectorRegistry = REGISTRY,
111+
_labelvalues: Optional[Sequence[str]] = None,
112112
) -> None:
113113
self._name = _build_full_name(self._type, name, namespace, subsystem, unit)
114114
self._labelnames = _validate_labelnames(self, labelnames)
@@ -269,7 +269,7 @@ def _metric_init(self) -> None:
269269
self._labelvalues)
270270
self._created = time.time()
271271

272-
def inc(self, amount: float=1, exemplar: Optional[Dict[str, str]]=None) -> None:
272+
def inc(self, amount: float = 1, exemplar: Optional[Dict[str, str]] = None) -> None:
273273
"""Increment counter by the given amount."""
274274
self._raise_if_not_observable()
275275
if amount < 0:
@@ -279,7 +279,7 @@ def inc(self, amount: float=1, exemplar: Optional[Dict[str, str]]=None) -> None:
279279
_validate_exemplar(exemplar)
280280
self._value.set_exemplar(Exemplar(exemplar, amount, time.time()))
281281

282-
def count_exceptions(self, exception: Type[BaseException]=Exception) -> ExceptionCounter:
282+
def count_exceptions(self, exception: Type[BaseException] = Exception) -> ExceptionCounter:
283283
"""Count exceptions in a block of code or function.
284284
285285
Can be used as a function decorator or context manager.
@@ -675,13 +675,13 @@ class Enum(MetricWrapperBase):
675675
def __init__(self,
676676
name: str,
677677
documentation: str,
678-
labelnames: Sequence[str]=(),
679-
namespace: str='',
680-
subsystem: str='',
681-
unit: str='',
682-
registry: CollectorRegistry=REGISTRY,
683-
_labelvalues: Optional[Sequence[str]]=None,
684-
states: Optional[Sequence[str]]=None,
678+
labelnames: Sequence[str] = (),
679+
namespace: str = '',
680+
subsystem: str = '',
681+
unit: str = '',
682+
registry: CollectorRegistry = REGISTRY,
683+
_labelvalues: Optional[Sequence[str]] = None,
684+
states: Optional[Sequence[str]] = None,
685685
):
686686
super().__init__(
687687
name=name,

0 commit comments

Comments
 (0)
0