Skip to content

Commit

Permalink
Fix typing build errors
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
csmarchbanks committed Dec 1, 2021
1 parent 822b8e9 commit 7c44be2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
10 changes: 6 additions & 4 deletions prometheus_client/context_managers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from timeit import default_timer
from types import TracebackType
from typing import (
Any, Callable, Literal, Optional, Type, TYPE_CHECKING, TypeVar,
)
from typing import Any, Callable, Optional, Type, TYPE_CHECKING, TypeVar

if sys.version_info >= (3, 8, 0):
from typing import Literal

from .decorator import decorate

Expand All @@ -19,7 +21,7 @@ def __init__(self, counter: "Counter", exception: Type[BaseException]) -> None:
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
Expand Down
30 changes: 15 additions & 15 deletions prometheus_client/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ def __repr__(self):
def __init__(self: T,
name: str,
documentation: str,
labelnames: Sequence[str]=(),
namespace: str='',
subsystem: str='',
unit: str='',
registry: CollectorRegistry=REGISTRY,
_labelvalues: Optional[Sequence[str]]=None,
labelnames: Sequence[str] = (),
namespace: str = '',
subsystem: str = '',
unit: str = '',
registry: CollectorRegistry = REGISTRY,
_labelvalues: Optional[Sequence[str]] = None,
) -> None:
self._name = _build_full_name(self._type, name, namespace, subsystem, unit)
self._labelnames = _validate_labelnames(self, labelnames)
Expand Down Expand Up @@ -269,7 +269,7 @@ def _metric_init(self) -> None:
self._labelvalues)
self._created = time.time()

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

def count_exceptions(self, exception: Type[BaseException]=Exception) -> ExceptionCounter:
def count_exceptions(self, exception: Type[BaseException] = Exception) -> ExceptionCounter:
"""Count exceptions in a block of code or function.
Can be used as a function decorator or context manager.
Expand Down Expand Up @@ -675,13 +675,13 @@ class Enum(MetricWrapperBase):
def __init__(self,
name: str,
documentation: str,
labelnames: Sequence[str]=(),
namespace: str='',
subsystem: str='',
unit: str='',
registry: CollectorRegistry=REGISTRY,
_labelvalues: Optional[Sequence[str]]=None,
states: Optional[Sequence[str]]=None,
labelnames: Sequence[str] = (),
namespace: str = '',
subsystem: str = '',
unit: str = '',
registry: CollectorRegistry = REGISTRY,
_labelvalues: Optional[Sequence[str]] = None,
states: Optional[Sequence[str]] = None,
):
super().__init__(
name=name,
Expand Down

0 comments on commit 7c44be2

Please sign in to comment.