From 34e42027cc3665d6901342031e508cc4125f9d8f Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Wed, 9 Aug 2023 13:34:55 +0200 Subject: [PATCH] platform module: Fixes interpreter version recognition the previous, human-oriented approach based on Guido's unmaterialized thought to continue with a version 4 after 3.9. --- CHANGES.rst | 2 +- cerberus/errors.py | 5 +++-- cerberus/platform.py | 9 +++------ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0c6eb5eb..a8772f63 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,7 @@ Cerberus is a collaboratively funded project, see the `funding page`_. Version 1.3.5 ------------- -Unreleased. +Released on August 9, 2023. New ~~~ diff --git a/cerberus/errors.py b/cerberus/errors.py index 97afc045..5e20e211 100644 --- a/cerberus/errors.py +++ b/cerberus/errors.py @@ -3,12 +3,13 @@ from __future__ import absolute_import +import sys from collections import defaultdict, namedtuple from copy import copy, deepcopy from functools import wraps from pprint import pformat -from cerberus.platform import PYTHON_VERSION, MutableMapping +from cerberus.platform import MutableMapping from cerberus.utils import compare_paths_lt, quote_string @@ -456,7 +457,7 @@ def _encode(value): error.info = _encode(error.info) return f(obj, error) - return wrapped if PYTHON_VERSION < 3 else f + return wrapped if sys.version_info < (3,) else f class BasicErrorHandler(BaseErrorHandler): diff --git a/cerberus/platform.py b/cerberus/platform.py index 796597ce..15b1eddd 100644 --- a/cerberus/platform.py +++ b/cerberus/platform.py @@ -6,10 +6,7 @@ raise RuntimeError("Cerberus can't be run with Python's optimization level 2.") -PYTHON_VERSION = float(sys.version_info[0]) + float(sys.version_info[1]) / 10 - - -if PYTHON_VERSION < 3: +if sys.version_info < (3,): _int_types = (int, long) # noqa: F821 _str_type = basestring # noqa: F821 else: @@ -17,7 +14,7 @@ _str_type = str -if PYTHON_VERSION < 3.3: +if sys.version_info < (3, 3): from collections import ( Callable, Container, @@ -42,7 +39,7 @@ Sized, ) -if PYTHON_VERSION < 3.8: +if sys.version_info < (3, 8): import importlib_metadata else: import importlib.metadata as importlib_metadata