From ea98f9fb7c76264df5e600ed597b79713e6cb2ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 18 Aug 2019 18:45:16 +0200 Subject: Drop support for Python<3.4. --- semantic_version/base.py | 25 +++++++++++++++---------- semantic_version/compat.py | 15 --------------- semantic_version/django_fields.py | 9 ++++----- 3 files changed, 19 insertions(+), 30 deletions(-) delete mode 100644 semantic_version/compat.py (limited to 'semantic_version') diff --git a/semantic_version/base.py b/semantic_version/base.py index 8d9098d..93291e7 100644 --- a/semantic_version/base.py +++ b/semantic_version/base.py @@ -2,15 +2,10 @@ # Copyright (c) The python-semanticversion project # This code is distributed under the two-clause BSD License. -from __future__ import unicode_literals - import functools import re -from .compat import base_cmp - - def _to_int(value): try: return int(value), True @@ -25,6 +20,17 @@ def _has_leading_zero(value): and value != '0') +def base_cmp(x, y): + if x == y: + return 0 + elif x > y: + return 1 + elif x < y: + return -1 + else: + return NotImplemented + + def identifier_cmp(a, b): """Compare two identifier (for pre-release/build components).""" @@ -68,7 +74,7 @@ def identifier_list_cmp(a, b): return base_cmp(len(a), len(b)) -class Version(object): +class Version: version_re = re.compile(r'^(\d+)\.(\d+)\.(\d+)(?:-([0-9a-zA-Z.-]+))?(?:\+([0-9a-zA-Z.-]+))?$') partial_version_re = re.compile(r'^(\d+)(?:\.(\d+)(?:\.(\d+))?)?(?:-([0-9a-zA-Z.-]*))?(?:\+([0-9a-zA-Z.-]*))?$') @@ -82,8 +88,7 @@ class Version(object): patch=None, prerelease=None, build=None, - partial=False, - ): + partial=False): has_text = version_string is not None has_parts = not (major is minor is patch is prerelease is build is None) if not has_text ^ has_parts: @@ -467,7 +472,7 @@ class Version(object): return self.__compare_helper(other, lambda x: x >= 0, notimpl_target=False) -class SpecItem(object): +class SpecItem: """A requirement specification.""" KIND_ANY = '*' @@ -570,7 +575,7 @@ class SpecItem(object): return hash((self.kind, self.spec)) -class Spec(object): +class Spec: def __init__(self, *specs_strings): subspecs = [self.parse(spec) for spec in specs_strings] self.specs = sum(subspecs, ()) diff --git a/semantic_version/compat.py b/semantic_version/compat.py deleted file mode 100644 index b17468f..0000000 --- a/semantic_version/compat.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -# Copyright (c) The python-semanticversion project -# This code is distributed under the two-clause BSD License. - - -def base_cmp(x, y): - if x == y: - return 0 - elif x > y: - return 1 - elif x < y: - return -1 - else: - # Fix Py2's behavior: cmp(x, y) returns -1 for unorderable types - return NotImplemented diff --git a/semantic_version/django_fields.py b/semantic_version/django_fields.py index 39a6c4b..2e9be69 100644 --- a/semantic_version/django_fields.py +++ b/semantic_version/django_fields.py @@ -2,7 +2,6 @@ # Copyright (c) The python-semanticversion project # This code is distributed under the two-clause BSD License. -from __future__ import unicode_literals from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -14,7 +13,7 @@ class SemVerField(models.CharField): def __init__(self, *args, **kwargs): kwargs.setdefault('max_length', 200) - super(SemVerField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def from_db_value(self, value, expression, connection, context): """Convert from the database format. @@ -36,7 +35,7 @@ class SemVerField(models.CharField): return str(value) def run_validators(self, value): - return super(SemVerField, self).run_validators(str(value)) + return super().run_validators(str(value)) class VersionField(SemVerField): @@ -48,11 +47,11 @@ class VersionField(SemVerField): def __init__(self, *args, **kwargs): self.partial = kwargs.pop('partial', False) self.coerce = kwargs.pop('coerce', False) - super(VersionField, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def deconstruct(self): """Handle django.db.migrations.""" - name, path, args, kwargs = super(VersionField, self).deconstruct() + name, path, args, kwargs = super().deconstruct() kwargs['partial'] = self.partial kwargs['coerce'] = self.coerce return name, path, args, kwargs -- cgit v1.2.1