Skip to content

Commit 6330837

Browse files
committed
from python<=3.7 support
According to https://endoflife.date/python python 3.7 support has been EOSed 27 Jun 2023. Pass all code over `pyupgrade --py38`. Signed-off-by: Tomasz Kłoczko <[email protected]>
1 parent 0e8d804 commit 6330837

24 files changed

+55
-84
lines changed

deprecated/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
Deprecated Library
43
==================
@@ -8,7 +7,7 @@
87
"""
98

109
__version__ = "1.2.14"
11-
__author__ = u"Laurent LAPORTE <[email protected]>"
10+
__author__ = "Laurent LAPORTE <[email protected]>"
1211
__date__ = "2023-05-27"
1312
__credits__ = "(c) Laurent LAPORTE"
1413

deprecated/classic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""
32
Classic deprecation warning
43
===========================
@@ -29,7 +28,7 @@
2928
else:
3029
_class_stacklevel = 3
3130

32-
string_types = (type(b''), type(u''))
31+
string_types = (bytes, str)
3332

3433

3534
class ClassicAdapter(wrapt.AdapterFactory):
@@ -124,7 +123,7 @@ def __init__(self, reason="", version="", action=None, category=DeprecationWarni
124123
self.action = action
125124
self.category = category
126125
self.extra_stacklevel = extra_stacklevel
127-
super(ClassicAdapter, self).__init__()
126+
super().__init__()
128127

129128
def get_deprecated_msg(self, wrapped, instance):
130129
"""

deprecated/sphinx.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
"""
32
Sphinx directive integration
43
============================
@@ -97,7 +96,7 @@ def __init__(
9796
raise ValueError("'version' argument is required in Sphinx directives")
9897
self.directive = directive
9998
self.line_length = line_length
100-
super(SphinxAdapter, self).__init__(
99+
super().__init__(
101100
reason=reason, version=version, action=action, category=category, extra_stacklevel=extra_stacklevel
102101
)
103102

@@ -141,12 +140,12 @@ def __call__(self, wrapped):
141140
docstring = "\n"
142141

143142
# -- append the directive division to the docstring
144-
docstring += "".join("{}\n".format(line) for line in div_lines)
143+
docstring += "".join(f"{line}\n" for line in div_lines)
145144

146145
wrapped.__doc__ = docstring
147146
if self.directive in {"versionadded", "versionchanged"}:
148147
return wrapped
149-
return super(SphinxAdapter, self).__call__(wrapped)
148+
return super().__call__(wrapped)
150149

151150
def get_deprecated_msg(self, wrapped, instance):
152151
"""
@@ -162,7 +161,7 @@ def get_deprecated_msg(self, wrapped, instance):
162161
Strip Sphinx cross-referencing syntax from warning message.
163162
164163
"""
165-
msg = super(SphinxAdapter, self).get_deprecated_msg(wrapped, instance)
164+
msg = super().get_deprecated_msg(wrapped, instance)
166165
# Strip Sphinx cross-reference syntax (like ":function:", ":py:func:" and ":py:meth:")
167166
# Possible values are ":role:`foo`", ":domain:role:`foo`"
168167
# where ``role`` and ``domain`` should match "[a-zA-Z]+"

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env python3
2-
# -*- coding: utf-8 -*-
32
#
43
# Deprecated Library Documentation build configuration file, created by
54
# sphinx-quickstart on Wed Jul 19 22:23:11 2017.

docs/source/sphinx/sphinx_demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
from deprecated.sphinx import deprecated
32
from deprecated.sphinx import versionadded
43
from deprecated.sphinx import versionchanged

docs/source/tutorial/v0/liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
""" Liberty library is free """
32

43
import pprint

docs/source/tutorial/v1/liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
""" Liberty library is free """
32

43
import pprint

docs/source/tutorial/v1/using_liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import liberty
32

43
liberty.print_value("hello")

docs/source/tutorial/v2/liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
""" Liberty library is free """
32

43
import pprint

docs/source/tutorial/v2/using_liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import liberty
32

43
liberty.print_value("hello")

docs/source/tutorial/v3/liberty.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# coding: utf-8
21
""" Liberty library is free """
32

43
import pprint
54

65
from deprecated import deprecated
76

87

9-
class Liberty(object):
8+
class Liberty:
109
def __init__(self, value):
1110
self.value = value
1211

docs/source/tutorial/v3/using_liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import liberty
32

43
obj = liberty.Liberty("Greeting")

docs/source/tutorial/v4/liberty.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
""" Liberty library is free """
32

43
import pprint
@@ -7,7 +6,7 @@
76

87

98
@deprecated("This class is not perfect")
10-
class Liberty(object):
9+
class Liberty:
1110
def __init__(self, value):
1211
self.value = value
1312

docs/source/tutorial/v4/using_liberty.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import liberty
32

43
obj = liberty.Liberty("Salutation")

docs/source/tutorial/warning_ctrl/extra_stacklevel_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55

66
@deprecated(version='1.0', extra_stacklevel=1)
7-
class MyObject(object):
7+
class MyObject:
88
def __init__(self, name):
99
self.name = name
1010

1111
def __str__(self):
12-
return "object: {name}".format(name=self.name)
12+
return f"object: {self.name}"
1313

1414

1515
def create_object(name):

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
u"""
2+
"""
43
Deprecated Library
54
------------------
65

tests/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# coding: utf-8
21
import pkg_resources
32

43
import deprecated

tests/test_deprecated.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
import inspect
32
import sys
43
import warnings
@@ -52,15 +51,15 @@ def classic_deprecated_class(request):
5251
if request.param is None:
5352

5453
@deprecated.classic.deprecated
55-
class Foo2(object):
54+
class Foo2:
5655
pass
5756

5857
return Foo2
5958
else:
6059
args, kwargs = request.param
6160

6261
@deprecated.classic.deprecated(*args, **kwargs)
63-
class Foo2(object):
62+
class Foo2:
6463
pass
6564

6665
return Foo2
@@ -70,7 +69,7 @@ class Foo2(object):
7069
def classic_deprecated_method(request):
7170
if request.param is None:
7271

73-
class Foo3(object):
72+
class Foo3:
7473
@deprecated.classic.deprecated
7574
def foo3(self):
7675
pass
@@ -79,7 +78,7 @@ def foo3(self):
7978
else:
8079
args, kwargs = request.param
8180

82-
class Foo3(object):
81+
class Foo3:
8382
@deprecated.classic.deprecated(*args, **kwargs)
8483
def foo3(self):
8584
pass
@@ -91,7 +90,7 @@ def foo3(self):
9190
def classic_deprecated_static_method(request):
9291
if request.param is None:
9392

94-
class Foo4(object):
93+
class Foo4:
9594
@staticmethod
9695
@deprecated.classic.deprecated
9796
def foo4():
@@ -101,7 +100,7 @@ def foo4():
101100
else:
102101
args, kwargs = request.param
103102

104-
class Foo4(object):
103+
class Foo4:
105104
@staticmethod
106105
@deprecated.classic.deprecated(*args, **kwargs)
107106
def foo4():
@@ -114,7 +113,7 @@ def foo4():
114113
def classic_deprecated_class_method(request):
115114
if request.param is None:
116115

117-
class Foo5(object):
116+
class Foo5:
118117
@classmethod
119118
@deprecated.classic.deprecated
120119
def foo5(cls):
@@ -124,7 +123,7 @@ def foo5(cls):
124123
else:
125124
args, kwargs = request.param
126125

127-
class Foo5(object):
126+
class Foo5:
128127
@classmethod
129128
@deprecated.classic.deprecated(*args, **kwargs)
130129
def foo5(cls):

tests/test_deprecated_class.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding: utf-8
2-
from __future__ import print_function
3-
41
import inspect
52
import io
63
import warnings
@@ -14,10 +11,10 @@ def test_simple_class_deprecation():
1411

1512
# To deprecate a class, it is better to emit a message when ``__new__`` is called.
1613
# The simplest way is to override the ``__new__``method.
17-
class MyBaseClass(object):
14+
class MyBaseClass:
1815
def __new__(cls, *args, **kwargs):
19-
print(u"I am deprecated!", file=stream)
20-
return super(MyBaseClass, cls).__new__(cls, *args, **kwargs)
16+
print("I am deprecated!", file=stream)
17+
return super().__new__(cls, *args, **kwargs)
2118

2219
# Of course, the subclass will be deprecated too
2320
class MySubClass(MyBaseClass):
@@ -26,14 +23,14 @@ class MySubClass(MyBaseClass):
2623
obj = MySubClass()
2724
assert isinstance(obj, MyBaseClass)
2825
assert inspect.isclass(MyBaseClass)
29-
assert stream.getvalue().strip() == u"I am deprecated!"
26+
assert stream.getvalue().strip() == "I am deprecated!"
3027

3128

3229
def test_class_deprecation_using_wrapper():
3330
# stream is used to store the deprecation message for testing
3431
stream = io.StringIO()
3532

36-
class MyBaseClass(object):
33+
class MyBaseClass:
3734
pass
3835

3936
# To deprecated the class, we use a wrapper function which emits
@@ -42,7 +39,7 @@ class MyBaseClass(object):
4239
original_new = MyBaseClass.__new__
4340

4441
def wrapped_new(unused, *args, **kwargs):
45-
print(u"I am deprecated!", file=stream)
42+
print("I am deprecated!", file=stream)
4643
return original_new(*args, **kwargs)
4744

4845
# Like ``__new__``, this wrapper is a class method.
@@ -55,7 +52,7 @@ class MySubClass(MyBaseClass):
5552
obj = MySubClass()
5653
assert isinstance(obj, MyBaseClass)
5754
assert inspect.isclass(MyBaseClass)
58-
assert stream.getvalue().strip() == u"I am deprecated!"
55+
assert stream.getvalue().strip() == "I am deprecated!"
5956

6057

6158
def test_class_deprecation_using_a_simple_decorator():
@@ -69,14 +66,14 @@ def simple_decorator(wrapped_cls):
6966
old_new = wrapped_cls.__new__
7067

7168
def wrapped_new(unused, *args, **kwargs):
72-
print(u"I am deprecated!", file=stream)
69+
print("I am deprecated!", file=stream)
7370
return old_new(*args, **kwargs)
7471

7572
wrapped_cls.__new__ = classmethod(wrapped_new)
7673
return wrapped_cls
7774

7875
@simple_decorator
79-
class MyBaseClass(object):
76+
class MyBaseClass:
8077
pass
8178

8279
class MySubClass(MyBaseClass):
@@ -85,12 +82,12 @@ class MySubClass(MyBaseClass):
8582
obj = MySubClass()
8683
assert isinstance(obj, MyBaseClass)
8784
assert inspect.isclass(MyBaseClass)
88-
assert stream.getvalue().strip() == u"I am deprecated!"
85+
assert stream.getvalue().strip() == "I am deprecated!"
8986

9087

9188
def test_class_deprecation_using_deprecated_decorator():
9289
@deprecated.classic.deprecated
93-
class MyBaseClass(object):
90+
class MyBaseClass:
9491
pass
9592

9693
class MySubClass(MyBaseClass):
@@ -108,7 +105,7 @@ class MySubClass(MyBaseClass):
108105

109106
def test_class_respect_global_filter():
110107
@deprecated.classic.deprecated
111-
class MyBaseClass(object):
108+
class MyBaseClass:
112109
pass
113110

114111
with warnings.catch_warnings(record=True) as warns:
@@ -121,7 +118,7 @@ class MyBaseClass(object):
121118

122119
def test_subclass_deprecation_using_deprecated_decorator():
123120
@deprecated.classic.deprecated
124-
class MyBaseClass(object):
121+
class MyBaseClass:
125122
pass
126123

127124
@deprecated.classic.deprecated
@@ -140,9 +137,9 @@ class MySubClass(MyBaseClass):
140137

141138
def test_simple_class_deprecation_with_args():
142139
@deprecated.classic.deprecated('kwargs class')
143-
class MyClass(object):
140+
class MyClass:
144141
def __init__(self, arg):
145-
super(MyClass, self).__init__()
142+
super().__init__()
146143
self.args = arg
147144

148145
MyClass(5)

0 commit comments

Comments
 (0)