Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop python<=3.7 support #71

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion deprecated/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Deprecated Library
==================
Expand Down
5 changes: 2 additions & 3 deletions deprecated/classic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Classic deprecation warning
===========================
Expand Down Expand Up @@ -29,7 +28,7 @@
else:
_class_stacklevel = 3

string_types = (type(b''), type(u''))
string_types = (bytes, str)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Python 2.7, it was common practice to use a definition such as string_types = (bytes, str) to manage str and byte arrays. However, this backward compatibility is no longer necessary, as Python 3 has clearly differentiated between str (Unicode text) and bytes (binary data).
To modernize the code, we should eliminate string_types and use str directly.



class ClassicAdapter(wrapt.AdapterFactory):
Expand Down Expand Up @@ -124,7 +123,7 @@ def __init__(self, reason="", version="", action=None, category=DeprecationWarni
self.action = action
self.category = category
self.extra_stacklevel = extra_stacklevel
super(ClassicAdapter, self).__init__()
super().__init__()

def get_deprecated_msg(self, wrapped, instance):
"""
Expand Down
9 changes: 4 additions & 5 deletions deprecated/sphinx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
"""
Sphinx directive integration
============================
Expand Down Expand Up @@ -97,7 +96,7 @@ def __init__(
raise ValueError("'version' argument is required in Sphinx directives")
self.directive = directive
self.line_length = line_length
super(SphinxAdapter, self).__init__(
super().__init__(
reason=reason, version=version, action=action, category=category, extra_stacklevel=extra_stacklevel
)

Expand Down Expand Up @@ -141,12 +140,12 @@ def __call__(self, wrapped):
docstring = "\n"

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

wrapped.__doc__ = docstring
if self.directive in {"versionadded", "versionchanged"}:
return wrapped
return super(SphinxAdapter, self).__call__(wrapped)
return super().__call__(wrapped)

def get_deprecated_msg(self, wrapped, instance):
"""
Expand All @@ -162,7 +161,7 @@ def get_deprecated_msg(self, wrapped, instance):
Strip Sphinx cross-referencing syntax from warning message.

"""
msg = super(SphinxAdapter, self).get_deprecated_msg(wrapped, instance)
msg = super().get_deprecated_msg(wrapped, instance)
# Strip Sphinx cross-reference syntax (like ":function:", ":py:func:" and ":py:meth:")
# Possible values are ":role:`foo`", ":domain:role:`foo`"
# where ``role`` and ``domain`` should match "[a-zA-Z]+"
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Deprecated Library Documentation build configuration file, created by
# sphinx-quickstart on Wed Jul 19 22:23:11 2017.
Expand Down
1 change: 0 additions & 1 deletion docs/source/sphinx/sphinx_demo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
from deprecated.sphinx import deprecated
from deprecated.sphinx import versionadded
from deprecated.sphinx import versionchanged
Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v0/liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
""" Liberty library is free """

import pprint
Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v1/liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
""" Liberty library is free """

import pprint
Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v1/using_liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import liberty

liberty.print_value("hello")
Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v2/liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
""" Liberty library is free """

import pprint
Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v2/using_liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import liberty

liberty.print_value("hello")
Expand Down
3 changes: 1 addition & 2 deletions docs/source/tutorial/v3/liberty.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: utf-8
""" Liberty library is free """

import pprint

from deprecated import deprecated


class Liberty(object):
class Liberty:
def __init__(self, value):
self.value = value

Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v3/using_liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import liberty

obj = liberty.Liberty("Greeting")
Expand Down
3 changes: 1 addition & 2 deletions docs/source/tutorial/v4/liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
""" Liberty library is free """

import pprint
Expand All @@ -7,7 +6,7 @@


@deprecated("This class is not perfect")
class Liberty(object):
class Liberty:
def __init__(self, value):
self.value = value

Expand Down
1 change: 0 additions & 1 deletion docs/source/tutorial/v4/using_liberty.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import liberty

obj = liberty.Liberty("Salutation")
Expand Down
4 changes: 2 additions & 2 deletions docs/source/tutorial/warning_ctrl/extra_stacklevel_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


@deprecated(version='1.0', extra_stacklevel=1)
class MyObject(object):
class MyObject:
def __init__(self, name):
self.name = name

def __str__(self):
return "object: {name}".format(name=self.name)
return f"object: {self.name}"


def create_object(name):
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
u"""
"""
Deprecated Library
------------------

Expand Down
1 change: 0 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
import pkg_resources

import deprecated
Expand Down
17 changes: 8 additions & 9 deletions tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import inspect
import sys
import warnings
Expand Down Expand Up @@ -52,15 +51,15 @@ def classic_deprecated_class(request):
if request.param is None:

@deprecated.classic.deprecated
class Foo2(object):
class Foo2:
pass

return Foo2
else:
args, kwargs = request.param

@deprecated.classic.deprecated(*args, **kwargs)
class Foo2(object):
class Foo2:
pass

return Foo2
Expand All @@ -70,7 +69,7 @@ class Foo2(object):
def classic_deprecated_method(request):
if request.param is None:

class Foo3(object):
class Foo3:
@deprecated.classic.deprecated
def foo3(self):
pass
Expand All @@ -79,7 +78,7 @@ def foo3(self):
else:
args, kwargs = request.param

class Foo3(object):
class Foo3:
@deprecated.classic.deprecated(*args, **kwargs)
def foo3(self):
pass
Expand All @@ -91,7 +90,7 @@ def foo3(self):
def classic_deprecated_static_method(request):
if request.param is None:

class Foo4(object):
class Foo4:
@staticmethod
@deprecated.classic.deprecated
def foo4():
Expand All @@ -101,7 +100,7 @@ def foo4():
else:
args, kwargs = request.param

class Foo4(object):
class Foo4:
@staticmethod
@deprecated.classic.deprecated(*args, **kwargs)
def foo4():
Expand All @@ -114,7 +113,7 @@ def foo4():
def classic_deprecated_class_method(request):
if request.param is None:

class Foo5(object):
class Foo5:
@classmethod
@deprecated.classic.deprecated
def foo5(cls):
Expand All @@ -124,7 +123,7 @@ def foo5(cls):
else:
args, kwargs = request.param

class Foo5(object):
class Foo5:
@classmethod
@deprecated.classic.deprecated(*args, **kwargs)
def foo5(cls):
Expand Down
33 changes: 15 additions & 18 deletions tests/test_deprecated_class.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# coding: utf-8
from __future__ import print_function

import inspect
import io
import warnings
Expand All @@ -14,10 +11,10 @@ def test_simple_class_deprecation():

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

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


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

class MyBaseClass(object):
class MyBaseClass:
pass

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

def wrapped_new(unused, *args, **kwargs):
print(u"I am deprecated!", file=stream)
print("I am deprecated!", file=stream)
return original_new(*args, **kwargs)

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


def test_class_deprecation_using_a_simple_decorator():
Expand All @@ -69,14 +66,14 @@ def simple_decorator(wrapped_cls):
old_new = wrapped_cls.__new__

def wrapped_new(unused, *args, **kwargs):
print(u"I am deprecated!", file=stream)
print("I am deprecated!", file=stream)
return old_new(*args, **kwargs)

wrapped_cls.__new__ = classmethod(wrapped_new)
return wrapped_cls

@simple_decorator
class MyBaseClass(object):
class MyBaseClass:
pass

class MySubClass(MyBaseClass):
Expand All @@ -85,12 +82,12 @@ class MySubClass(MyBaseClass):
obj = MySubClass()
assert isinstance(obj, MyBaseClass)
assert inspect.isclass(MyBaseClass)
assert stream.getvalue().strip() == u"I am deprecated!"
assert stream.getvalue().strip() == "I am deprecated!"


def test_class_deprecation_using_deprecated_decorator():
@deprecated.classic.deprecated
class MyBaseClass(object):
class MyBaseClass:
pass

class MySubClass(MyBaseClass):
Expand All @@ -108,7 +105,7 @@ class MySubClass(MyBaseClass):

def test_class_respect_global_filter():
@deprecated.classic.deprecated
class MyBaseClass(object):
class MyBaseClass:
pass

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

def test_subclass_deprecation_using_deprecated_decorator():
@deprecated.classic.deprecated
class MyBaseClass(object):
class MyBaseClass:
pass

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

def test_simple_class_deprecation_with_args():
@deprecated.classic.deprecated('kwargs class')
class MyClass(object):
class MyClass:
def __init__(self, arg):
super(MyClass, self).__init__()
super().__init__()
self.args = arg

MyClass(5)
Expand Down
Loading