Skip to content

Commit 0e38b11

Browse files
committed
Merge branch 'removepy2' into develop
PR #274. * removepy2: Drop support for py2 and py <= 3.6
2 parents 4b7802d + f61b0cd commit 0e38b11

File tree

6 files changed

+17
-81
lines changed

6 files changed

+17
-81
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ubuntu-latest]
12-
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
12+
python-version: [3.7, 3.8, 3.9, "3.10"]
1313

1414
steps:
1515
- uses: actions/checkout@v2

jmespath/compat.py

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
11
import sys
22
import inspect
3+
from itertools import zip_longest
34

4-
PY2 = sys.version_info[0] == 2
55

6+
text_type = str
7+
string_type = str
68

7-
def with_metaclass(meta, *bases):
8-
# Taken from flask/six.
9-
class metaclass(meta):
10-
def __new__(cls, name, this_bases, d):
11-
return meta(name, bases, d)
12-
return type.__new__(metaclass, 'temporary_class', (), {})
139

10+
def with_str_method(cls):
11+
# In python3, we don't need to do anything, we return a str type.
12+
return cls
1413

15-
if PY2:
16-
text_type = unicode
17-
string_type = basestring
18-
from itertools import izip_longest as zip_longest
14+
def with_repr_method(cls):
15+
return cls
1916

20-
def with_str_method(cls):
21-
"""Class decorator that handles __str__ compat between py2 and py3."""
22-
# In python2, the __str__ should be __unicode__
23-
# and __str__ should return bytes.
24-
cls.__unicode__ = cls.__str__
25-
def __str__(self):
26-
return self.__unicode__().encode('utf-8')
27-
cls.__str__ = __str__
28-
return cls
29-
30-
def with_repr_method(cls):
31-
"""Class decorator that handle __repr__ with py2 and py3."""
32-
# This is almost the same thing as with_str_method *except*
33-
# it uses the unicode_escape encoding. This also means we need to be
34-
# careful encoding the input multiple times, so we only encode
35-
# if we get a unicode type.
36-
original_repr_method = cls.__repr__
37-
def __repr__(self):
38-
original_repr = original_repr_method(self)
39-
if isinstance(original_repr, text_type):
40-
original_repr = original_repr.encode('unicode_escape')
41-
return original_repr
42-
cls.__repr__ = __repr__
43-
return cls
44-
45-
def get_methods(cls):
46-
for name, method in inspect.getmembers(cls,
47-
predicate=inspect.ismethod):
48-
yield name, method
49-
50-
else:
51-
text_type = str
52-
string_type = str
53-
from itertools import zip_longest
54-
55-
def with_str_method(cls):
56-
# In python3, we don't need to do anything, we return a str type.
57-
return cls
58-
59-
def with_repr_method(cls):
60-
return cls
61-
62-
def get_methods(cls):
63-
for name, method in inspect.getmembers(cls,
64-
predicate=inspect.isfunction):
65-
yield name, method
17+
def get_methods(cls):
18+
for name, method in inspect.getmembers(cls, predicate=inspect.isfunction):
19+
yield name, method

jmespath/functions.py

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

44
from jmespath import exceptions
55
from jmespath.compat import string_type as STRING_TYPE
6-
from jmespath.compat import get_methods, with_metaclass
6+
from jmespath.compat import get_methods
77

88

99
# python types -> jmespath types
@@ -64,7 +64,7 @@ def _populate_function_table(cls):
6464
cls.FUNCTION_TABLE = function_table
6565

6666

67-
class Functions(with_metaclass(FunctionRegistry, object)):
67+
class Functions(metaclass=FunctionRegistry):
6868

6969
FUNCTION_TABLE = {
7070
}

setup.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
#!/usr/bin/env python
22

33
import io
4-
import sys
5-
import warnings
64

75
from setuptools import setup, find_packages
86

97

10-
if sys.version_info[:2] <= (2, 6) or ((3, 0) <= sys.version_info[:2] <= (3, 3)):
11-
python_ver = '.'.join(str(x) for x in sys.version_info[:3])
12-
13-
warnings.warn(
14-
'You are using Python {0}, which will no longer be supported in '
15-
'version 0.11.0'.format(python_ver),
16-
DeprecationWarning)
17-
18-
198
setup(
209
name='jmespath',
2110
version='0.10.0',
@@ -27,21 +16,14 @@
2716
scripts=['bin/jp.py'],
2817
packages=find_packages(exclude=['tests']),
2918
license='MIT',
30-
python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*',
19+
python_requires='>=3.7',
3120
classifiers=[
3221
'Development Status :: 5 - Production/Stable',
3322
'Intended Audience :: Developers',
3423
'Natural Language :: English',
3524
'License :: OSI Approved :: MIT License',
3625
'Programming Language :: Python',
37-
'Programming Language :: Python :: 2',
38-
'Programming Language :: Python :: 2.6',
39-
'Programming Language :: Python :: 2.7',
4026
'Programming Language :: Python :: 3',
41-
'Programming Language :: Python :: 3.3',
42-
'Programming Language :: Python :: 3.4',
43-
'Programming Language :: Python :: 3.5',
44-
'Programming Language :: Python :: 3.6',
4527
'Programming Language :: Python :: 3.7',
4628
'Programming Language :: Python :: 3.8',
4729
'Programming Language :: Python :: 3.9',

tests/test_lexer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_bad_first_character(self):
152152
tokens = list(self.lexer.tokenize('^foo[0]'))
153153

154154
def test_unknown_character_with_identifier(self):
155-
with self.assertRaisesRegexp(LexerError, "Unknown token"):
155+
with self.assertRaisesRegex(LexerError, "Unknown token"):
156156
list(self.lexer.tokenize('foo-bar'))
157157

158158

tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_bad_unicode_string(self):
169169
error_message = re.compile(
170170
r'Bad jmespath expression: '
171171
r'Invalid \\uXXXX escape.*\\uAZ12', re.DOTALL)
172-
with self.assertRaisesRegexp(exceptions.LexerError, error_message):
172+
with self.assertRaisesRegex(exceptions.LexerError, error_message):
173173
self.parser.parse(r'"\uAZ12"')
174174

175175

0 commit comments

Comments
 (0)