From 981f8342c7c8c131e02b37d2b2ae4de2726fd054 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 +++------ cerberus/tests/test_assorted.py | 7 ++++--- 4 files changed, 11 insertions(+), 12 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 diff --git a/cerberus/tests/test_assorted.py b/cerberus/tests/test_assorted.py index beb62c3d..e21a9b44 100644 --- a/cerberus/tests/test_assorted.py +++ b/cerberus/tests/test_assorted.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import sys from decimal import Decimal from pytest import mark @@ -8,12 +9,12 @@ from cerberus.tests import assert_fail, assert_success from cerberus.utils import validator_factory from cerberus.validator import BareValidator -from cerberus.platform import PYTHON_VERSION, importlib_metadata +from cerberus.platform import importlib_metadata -if PYTHON_VERSION > 3 and PYTHON_VERSION < 3.4: +if (3,) < sys.version_info < (3, 4): from imp import reload -elif PYTHON_VERSION >= 3.4: +elif sys.version_info >= (3, 4): from importlib import reload else: pass # Python 2.x