Skip to content

Commit eca6a53

Browse files
committed
Lets use six library.
This is cheaper, than re-implement the same. Pycharm code inspections is stored with project.
1 parent fc07266 commit eca6a53

File tree

9 files changed

+56
-67
lines changed

9 files changed

+56
-67
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGELOG
22
=========
3+
Version 2.2.1
4+
-------------
5+
* Use six library for compatibility options (anyway, it's required by modern setuptools).
6+
37
Version 2.2.0
48
-------------
59
* Async for python 3.4

logwrap/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
from __future__ import absolute_import
2626

27-
import sys
27+
import six
2828

2929
from ._log_wrap import logwrap, LogWrap
3030
from ._repr_utils import PrettyFormat, pretty_repr, pretty_str
3131

32-
__version__ = '2.2.0'
32+
__version__ = '2.2.1'
3333

3434
__all__ = (
3535
'logwrap',
@@ -39,7 +39,7 @@
3939
)
4040

4141
# pylint: disable=ungrouped-imports, no-name-in-module
42-
if sys.version_info[0:2] >= (3, 4):
42+
if six.PY34:
4343
from ._alogwrap import async_logwrap, AsyncLogWrap
4444

4545
__all__ += ('async_logwrap', 'AsyncLogWrap')

logwrap/_alogwrap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from __future__ import absolute_import
2424
from __future__ import unicode_literals
2525

26+
# noinspection PyCompatibility
2627
import asyncio
2728
import functools
2829
import inspect
@@ -52,7 +53,7 @@ def _get_function_wrapper(
5253
sig = inspect.signature(obj=self._spec or func)
5354

5455
# pylint: disable=missing-docstring
55-
# noinspection PyCompatibility
56+
# noinspection PyCompatibility,PyMissingOrEmptyDocstring
5657
@functools.wraps(func)
5758
@asyncio.coroutine
5859
def wrapper(*args, **kwargs):

logwrap/_formatters.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,12 @@
1414
from __future__ import absolute_import
1515
from __future__ import unicode_literals
1616

17-
import sys
18-
19-
_PY3 = sys.version_info[0:2] > (3, 0)
20-
21-
if _PY3:
22-
binary_type = bytes
23-
text_type = str
24-
else:
25-
binary_type = str
26-
# pylint: disable=unicode-builtin, undefined-variable
27-
# noinspection PyUnresolvedReferences
28-
text_type = unicode # NOQA
29-
# pylint: enable=unicode-builtin, undefined-variable
17+
import six
3018

3119

3220
def _strings_repr(indent, val):
3321
"""Custom repr for strings and binary strings."""
34-
if isinstance(val, binary_type):
22+
if isinstance(val, six.binary_type):
3523
val = val.decode(
3624
encoding='utf-8',
3725
errors='backslashreplace'
@@ -66,8 +54,8 @@ def _set_repr(indent, val):
6654
s_repr_formatters = {
6755
'default': "{spc:<{indent}}{val!r}".format,
6856
set: _set_repr,
69-
binary_type: _strings_repr,
70-
text_type: _strings_repr,
57+
six.binary_type: _strings_repr,
58+
six.text_type: _strings_repr,
7159
}
7260

7361

@@ -85,7 +73,7 @@ def _set_repr(indent, val):
8573

8674
def _strings_str(indent, val):
8775
"""Custom repr for strings and binary strings."""
88-
if isinstance(val, binary_type):
76+
if isinstance(val, six.binary_type):
8977
val = val.decode(
9078
encoding='utf-8',
9179
errors='backslashreplace'
@@ -116,8 +104,8 @@ def _set_str(indent, val):
116104
s_str_formatters = {
117105
'default': "{spc:<{indent}}{val!s}".format,
118106
set: _set_str,
119-
binary_type: _strings_str,
120-
text_type: _strings_str,
107+
six.binary_type: _strings_str,
108+
six.text_type: _strings_str,
121109
}
122110

123111

logwrap/_log_wrap.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
from __future__ import unicode_literals
2525

2626
import logging
27-
import sys
2827
import warnings
2928

29+
import six
30+
3031
from . import _log_wrap_shared
3132

3233
# pylint: disable=ungrouped-imports, no-name-in-module
33-
if sys.version_info[0:2] > (3, 0):
34+
if six.PY34:
3435
from inspect import signature
3536
else:
3637
# noinspection PyUnresolvedReferences
@@ -50,10 +51,11 @@ def _get_function_wrapper(self, func):
5051
:type func: types.FunctionType
5152
:rtype: types.FunctionType
5253
"""
53-
if sys.version_info[0:2] >= (3, 4):
54+
if six.PY34:
5455
# pylint: disable=exec-used, expression-not-assigned
55-
# Exec is required due to python<3.5 hasn't this methods
56+
# Exec is required due to python<3.4 hasn't this methods
5657
ns = {'func': func}
58+
# noinspection PyStatementEffect
5759
exec( # nosec
5860
"""
5961
from asyncio import iscoroutinefunction
@@ -73,7 +75,8 @@ def _get_function_wrapper(self, func):
7375
sig = signature(obj=self._spec or func)
7476

7577
# pylint: disable=missing-docstring
76-
@_log_wrap_shared.wraps(func)
78+
# noinspection PyMissingOrEmptyDocstring
79+
@six.wraps(func)
7780
def wrapper(*args, **kwargs):
7881
args_repr = self._get_func_args_repr(
7982
sig=sig,

logwrap/_log_wrap_shared.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import abc
2323
import functools
2424
import logging
25-
import sys
25+
26+
import six
2627

2728
import logwrap as core
2829

29-
__all__ = ('wraps', 'BaseLogWrap')
30+
__all__ = ('BaseLogWrap', )
3031

3132
logger = logging.getLogger(__name__)
3233

@@ -43,6 +44,7 @@ def _check_type(expected):
4344
def deco(func):
4445
"""Check type before asign."""
4546
# pylint: disable=missing-docstring
47+
# noinspection PyMissingOrEmptyDocstring
4648
@functools.wraps(func)
4749
def wrapper(self, val):
4850
if not isinstance(val, expected):
@@ -59,29 +61,10 @@ def wrapper(self, val):
5961
return deco
6062

6163

62-
if sys.version_info[0:2] < (3, 4):
63-
def wraps(
64-
wrapped,
65-
assigned=functools.WRAPPER_ASSIGNMENTS,
66-
updated=functools.WRAPPER_UPDATES
67-
):
68-
"""Backport of functools.wraps to older python versions."""
69-
# pylint: disable=missing-docstring
70-
def wrapper(f):
71-
f = functools.wraps(wrapped, assigned, updated)(f)
72-
f.__wrapped__ = wrapped
73-
return f
74-
75-
# pylint: enable=missing-docstring
76-
return wrapper
77-
else:
78-
wraps = functools.wraps
79-
80-
8164
class BaseLogWrap(
8265
type.__new__(
8366
abc.ABCMeta,
84-
'BaseMeta' if sys.version_info[0:2] > (3, 0) else b'BaseMeta',
67+
'BaseMeta' if six.PY3 else b'BaseMeta',
8568
(object, ),
8669
{}
8770
)
@@ -160,13 +143,15 @@ def __init__(
160143

161144
self.__wrap_func_self()
162145

146+
# We are not interested to pass any arguments to object
147+
# noinspection PyArgumentList
163148
super(BaseLogWrap, self).__init__()
164149

165150
def __wrap_func_self(self):
166151
"""Mark self as function wrapper. Usd only without arguments."""
167152
if self.__func is not None:
168153
functools.update_wrapper(self, self.__func)
169-
if sys.version_info[0:2] < (3, 4):
154+
if not six.PY34:
170155
self.__wrapped__ = self.__func
171156

172157
@property

logwrap/_repr_utils.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
from __future__ import absolute_import
2424
from __future__ import unicode_literals
2525

26-
import sys
2726
import types
2827

29-
_PY3 = sys.version_info[0:2] > (3, 0)
28+
import six
3029

3130
# pylint: disable=ungrouped-imports, no-name-in-module
32-
if _PY3:
31+
if six.PY3:
3332
from inspect import Parameter
3433
from inspect import signature
3534
else:
@@ -48,17 +47,6 @@
4847
# pylint: enable=wrong-import-position
4948

5049

51-
if _PY3:
52-
binary_type = bytes
53-
text_type = str
54-
else:
55-
binary_type = str
56-
# pylint: disable=unicode-builtin, undefined-variable
57-
# noinspection PyUnresolvedReferences
58-
text_type = unicode # NOQA
59-
# pylint: enable=unicode-builtin, undefined-variable
60-
61-
6250
def _known_callble(item):
6351
"""Check for possibility to parse callable."""
6452
return isinstance(item, (types.FunctionType, types.MethodType))
@@ -131,7 +119,7 @@ def __init__(
131119
self.__keyword = keyword
132120
self.__max_indent = max_indent
133121
self.__indent_step = indent_step
134-
self.__py2_str = py2_str and not _PY3 # Python 2 only behavior
122+
self.__py2_str = py2_str and not six.PY3 # Python 2 only behavior
135123

136124
@property
137125
def max_indent(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
'Decorator for logging function arguments by human-readable way'
6262
),
6363
long_description=long_description,
64-
requires=['six'],
64+
install_requires=['six'],
6565
extras_require={
6666
':python_version == "2.7"': [
6767
'funcsigs>=1.0',

0 commit comments

Comments
 (0)