10000 check Python version with sys.version_info (#227) · umax/client_python@d3562a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3562a1

Browse files
minrkbrian-brazil
authored andcommitted
check Python version with sys.version_info (prometheus#227)
sys.version_info is a parsed tuple of numbers, so not vulnerable to incorrect string version comparison (e.g. '10' < '3') Discovered because prometheus-client cannot be imported on development versions of Python which have version strings like `'3.7.0a0'`
1 parent 397eec5 commit d3562a1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

prometheus_client/decorator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
__version__ = '4.0.10'
4444

45-
if sys.version >= '3':
45+
if sys.version_info >= (3,):
4646
from inspect import getfullargspec
4747

4848
def get_init(cls):
@@ -109,7 +109,7 @@ def __init__(self, func=None, name=None, signature=None,
109109
setattr(self, a, getattr(argspec, a))
110110
for i, arg in enumerate(self.args):
111111
setattr(self, 'arg%d' % i, arg)
112-
if sys.version < '3': # easy way
112+
if sys.version_info < (3,): # easy way
113113
self.shortsignature = self.signature = (
114114
inspect.formatargspec(
115115
formatvalue=lambda val: "", *argspec)[1:-1])

prometheus_client/exposition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
2929
'''Content type of the latest text format'''
3030

31-
PYTHON26_OR_OLDER = tuple(int(val) for val in sys.version.split()[0].split('.')) < (2, 7, 0)
31+
PYTHON26_OR_OLDER = sys.version_info < (2, 7)
3232

3333
def make_wsgi_app(registry=core.REGISTRY):
3434
'''Create a WSGI app which serves the metrics from a registry.'''

0 commit comments

Comments
 (0)
0