8000 removed unused sys.version_info with python versions <3.8 around the … · draftcode/client_python@acad5e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit acad5e2

Browse files
committed
removed unused sys.version_info with python versions <3.8 around the codebase
Signed-off-by: rafsaf <rafal.safin12@gmail.com>
1 parent 654aece commit acad5e2

File tree

4 files changed

+25
-63
lines changed

4 files changed

+25
-63
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/decorator.py

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,18 @@
3535

3636
import collections
3737
import inspect
38+
from inspect import getfullargspec
3839
import itertools
3940
import operator
4041
import re
4142
import sys
4243

4344
__version__ = '4.0.10'
4445

45-
if sys.version_info >= (3,):
46-
from inspect import getfullargspec
4746

47+
def get_init(cls):
48+
return cls.__init__
4849

49-
def get_init(cls):
50-
return cls.__init__
51-
else:
52-
class getfullargspec(object):
53-
"A quick and dirty replacement for getfullargspec for Python 2.X"
54-
55-
def __init__(self, f):
56-
self.args, self.varargs, self.varkw, self.defaults = \
57-
inspect.getargspec(f)
58-
self.kwonlyargs = []
59-
self.kwonlydefaults = None
60-
61-
def __iter__(self):
62-
yield self.args
63-
yield self.varargs
64-
yield self.varkw
65-
yield self.defaults
66-
67-
getargspec = inspect.getargspec
68-
69-
70-
def get_init(cls):
71-
return cls.__init__.__func__
7250

7351
# getargspec has been deprecated in Python 3.5
7452
ArgSpec = collections.namedtuple(
@@ -113,26 +91,21 @@ def __init__(self, func=None, name=None, signature=None,
11391
setattr(self, a, getattr(argspec, a))
11492
for i, arg in enumerate(self.args):
11593
setattr(self, 'arg%d' % i, arg)
116-
if sys.version_info < (3,): # easy way
117-
self.shortsignature = self.signature = (
118-
inspect.formatargspec(
119-
formatvalue=lambda val: "", *argspec)[1:-1])
120-
else: # Python 3 way
121-
allargs = list(self.args)
122-
allshortargs = list(self.args)
123-
if self.varargs:
124-
allargs.append('*' + self.varargs)
125-
allshortargs.append('*' + self.varargs)
126-
elif self.kwonlyargs:
127-
allargs.append('*') # single star syntax
128-
for a in self.kwonlyargs:
129-
allargs.append('%s=None' % a)
130-
allshortargs.append('%s=%s' % (a, a))
131-
if self.varkw:
132-
allargs.append('**' + self.varkw)
133-
allshortargs.append('**' + self.varkw)
134-
self.signature = ', '.join(allargs)
135-
self.shortsignature = ', '.join(allshortargs)
94+
allargs = list(self.args)
95+
allshortargs = list(self.args)
96+
if self.varargs:
97+
allargs.append('*' + self.varargs)
98+
allshortargs.append('*' + self.varargs)
99+
elif self.kwonlyargs:
100+
allargs.append('*') # single star syntax
101+
for a in self.kwonlyargs:
102+
allargs.append('%s=None' % a)
103+
allshortargs.append('%s=%s' % (a, a))
104+
if self.varkw:
105+
allargs.append('**' + self.varkw)
106+
allshortargs.append('**' + self.varkw)
107+
self.signature = ', '.join(allargs)
108+
self.shortsignature = ', '.join(allshortargs)
136109
self.dict = func.__dict__.copy()
137110
# func=None happens when decorating a caller
138111
if name:

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import os
2-
import sys
32
from threading import Lock
43
import time
54
import types
65
from typing import (
7-
Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Type,
8-
TypeVar, Union,
6+
Any, Callable, Dict, Iterable, List, Literal, Optional, Sequence, Tuple,
7+
Type, TypeVar, Union,
98
)
109

1110
from . import values # retain this import style for testability
@@ -18,9 +17,6 @@
1817
from .samples import Exemplar, Sample
1918
from .utils import floatToGoString, INF
2019

21-
if sys.version_info >= (3, 8, 0):
22-
from typing import Literal
23-
2420
T = TypeVar('T', bound='MetricWrapperBase')
2521
F = TypeVar("F", bound=Callable[..., Any])
2622

@@ -361,7 +357,7 @@ def __init__(self,
361357
unit: str = '',
362358
registry: Optional[CollectorRegistry] = REGISTRY,
363359
_labelvalues: Optional[Sequence[str]] = None,
364-
multiprocess_mode: "Literal['all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum']" = 'all',
360+
multiprocess_mode: Literal['all', 'liveall', 'min', 'livemin', 'max', 'livemax', 'sum', 'livesum'] = 'all',
365361
):
366362
self._multiprocess_mode = multiprocess_mode
367363
if multiprocess_mode not in self._MULTIPROC_MODES:

0 commit comments

Comments
 (0)
0