From f61b0cd087e965e10602234615ede87d02f7644c Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Tue, 15 Mar 2022 13:25:37 -0400 Subject: [PATCH] Drop support for py2 and py <= 3.6 See #268. --- .github/workflows/run-tests.yml | 2 +- jmespath/compat.py | 68 ++++++--------------------------- jmespath/functions.py | 4 +- setup.py | 20 +--------- tests/test_lexer.py | 2 +- tests/test_parser.py | 2 +- 6 files changed, 17 insertions(+), 81 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0b07a258..119c290b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"] + python-version: [3.7, 3.8, 3.9, "3.10"] steps: - uses: actions/checkout@v2 diff --git a/jmespath/compat.py b/jmespath/compat.py index 2ed0fe78..50f8f277 100644 --- a/jmespath/compat.py +++ b/jmespath/compat.py @@ -1,65 +1,19 @@ import sys import inspect +from itertools import zip_longest -PY2 = sys.version_info[0] == 2 +text_type = str +string_type = str -def with_metaclass(meta, *bases): - # Taken from flask/six. - class metaclass(meta): - def __new__(cls, name, this_bases, d): - return meta(name, bases, d) - return type.__new__(metaclass, 'temporary_class', (), {}) +def with_str_method(cls): + # In python3, we don't need to do anything, we return a str type. + return cls -if PY2: - text_type = unicode - string_type = basestring - from itertools import izip_longest as zip_longest +def with_repr_method(cls): + return cls - def with_str_method(cls): - """Class decorator that handles __str__ compat between py2 and py3.""" - # In python2, the __str__ should be __unicode__ - # and __str__ should return bytes. - cls.__unicode__ = cls.__str__ - def __str__(self): - return self.__unicode__().encode('utf-8') - cls.__str__ = __str__ - return cls - - def with_repr_method(cls): - """Class decorator that handle __repr__ with py2 and py3.""" - # This is almost the same thing as with_str_method *except* - # it uses the unicode_escape encoding. This also means we need to be - # careful encoding the input multiple times, so we only encode - # if we get a unicode type. - original_repr_method = cls.__repr__ - def __repr__(self): - original_repr = original_repr_method(self) - if isinstance(original_repr, text_type): - original_repr = original_repr.encode('unicode_escape') - return original_repr - cls.__repr__ = __repr__ - return cls - - def get_methods(cls): - for name, method in inspect.getmembers(cls, - predicate=inspect.ismethod): - yield name, method - -else: - text_type = str - string_type = str - from itertools import zip_longest - - def with_str_method(cls): - # In python3, we don't need to do anything, we return a str type. - return cls - - def with_repr_method(cls): - return cls - - def get_methods(cls): - for name, method in inspect.getmembers(cls, - predicate=inspect.isfunction): - yield name, method +def get_methods(cls): + for name, method in inspect.getmembers(cls, predicate=inspect.isfunction): + yield name, method diff --git a/jmespath/functions.py b/jmespath/functions.py index 31dab051..11ab56ac 100644 --- a/jmespath/functions.py +++ b/jmespath/functions.py @@ -3,7 +3,7 @@ from jmespath import exceptions from jmespath.compat import string_type as STRING_TYPE -from jmespath.compat import get_methods, with_metaclass +from jmespath.compat import get_methods # python types -> jmespath types @@ -64,7 +64,7 @@ def _populate_function_table(cls): cls.FUNCTION_TABLE = function_table -class Functions(with_metaclass(FunctionRegistry, object)): +class Functions(metaclass=FunctionRegistry): FUNCTION_TABLE = { } diff --git a/setup.py b/setup.py index b2a27885..f81394f1 100644 --- a/setup.py +++ b/setup.py @@ -1,21 +1,10 @@ #!/usr/bin/env python import io -import sys -import warnings from setuptools import setup, find_packages -if sys.version_info[:2] <= (2, 6) or ((3, 0) <= sys.version_info[:2] <= (3, 3)): - python_ver = '.'.join(str(x) for x in sys.version_info[:3]) - - warnings.warn( - 'You are using Python {0}, which will no longer be supported in ' - 'version 0.11.0'.format(python_ver), - DeprecationWarning) - - setup( name='jmespath', version='0.10.0', @@ -27,21 +16,14 @@ scripts=['bin/jp.py'], packages=find_packages(exclude=['tests']), license='MIT', - python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*', + python_requires='>=3.7', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'Natural Language :: English', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', diff --git a/tests/test_lexer.py b/tests/test_lexer.py index 6d0dd2be..fbae0608 100644 --- a/tests/test_lexer.py +++ b/tests/test_lexer.py @@ -152,7 +152,7 @@ def test_bad_first_character(self): tokens = list(self.lexer.tokenize('^foo[0]')) def test_unknown_character_with_identifier(self): - with self.assertRaisesRegexp(LexerError, "Unknown token"): + with self.assertRaisesRegex(LexerError, "Unknown token"): list(self.lexer.tokenize('foo-bar')) diff --git a/tests/test_parser.py b/tests/test_parser.py index 5af5ce7f..8229bdef 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -169,7 +169,7 @@ def test_bad_unicode_string(self): error_message = re.compile( r'Bad jmespath expression: ' r'Invalid \\uXXXX escape.*\\uAZ12', re.DOTALL) - with self.assertRaisesRegexp(exceptions.LexerError, error_message): + with self.assertRaisesRegex(exceptions.LexerError, error_message): self.parser.parse(r'"\uAZ12"')