Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gauge typing improvement #935

Merged
merged 3 commits into from Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions 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:
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions prometheus_client/exposition.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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('/')
Expand Down
6 changes: 3 additions & 3 deletions prometheus_client/metrics.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down