Skip to content

Commit e27c917

Browse files
authored
Move forward: '5.0.0' with python 3.5+ only (#33)
No crushes on cythonize + exception inside async def Signatures inside, updated (mypy pass) py2str param is eliminated less code, less magic, less hell
1 parent 9830f3e commit e27c917

26 files changed

+805
-1897
lines changed

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ sudo: false
22
language: python
33
os: linux
44
python:
5-
- 2.7
6-
- 3.4
75
- 3.5
86
- 3.6
97
- &mainstream_python 3.7-dev
10-
- &pypy pypy
11-
- pypy3.5
8+
- &pypy pypy3.5
129
install:
1310
- &upgrade_python_toolset pip install --upgrade pip setuptools wheel
1411
- pip install tox-travis

CI_REQUIREMENTS.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
funcsigs >= 1.0
2-
mock; python_version == "2.7"
31
-r requirements.txt

README.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ Pros:
3939

4040
::
4141

42-
Python 2.7
43-
Python 3.4
4442
Python 3.5
4543
Python 3.6
4644
Python 3.7
47-
PyPy
4845
PyPy3 3.5+
4946

47+
.. note:: Python 3.4 and 2.7 is supported in versions < 5.0.0
48+
5049
This package includes helpers:
5150

5251
* `logwrap` - main helper. The same is `LogWrap`.
@@ -207,7 +206,6 @@ Signature is self-documenting:
207206
no_indent_start=False, # do not indent the first level
208207
max_indent=20, # maximum allowed indent level
209208
indent_step=4, # step between indents
210-
py2_str=False, # use bytes for python 2 __repr__ and __str__
211209
)
212210
213211
Limitation: Dict like objects is always marked inside `{}` for readability, even if it is `collections.OrderedDict` (standard repr as list of tuples).
@@ -225,7 +223,6 @@ Signature is self-documenting:
225223
no_indent_start=False, # do not indent the first level
226224
max_indent=20, # maximum allowed indent level
227225
indent_step=4, # step between indents
228-
py2_str=False, # use bytes for python 2 __repr__ and __str__
229226
)
230227
231228
Limitations:
@@ -248,7 +245,6 @@ Object signature:
248245
self,
249246
max_indent=20, # maximum allowed indent level
250247
indent_step=4, # step between indents
251-
py2_str=False, # use bytes for python 2 __repr__ and __str__
252248
)
253249
254250
Callable object (`PrettyFormat` instance) signature:

appveyor.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,6 @@ environment:
44
secure: TCKGf77kkVeo2Pbd+lQY5Q==
55

66
matrix:
7-
- PYTHON: "C:\\Python27-x64"
8-
PYTHON_VERSION: "2.7.x" # currently 2.7.11
9-
PYTHON_ARCH: "64"
10-
11-
- PYTHON: "C:\\Python34"
12-
PYTHON_VERSION: "3.4.x" # currently 3.4.3
13-
PYTHON_ARCH: "32"
14-
15-
- PYTHON: "C:\\Python34-x64"
16-
PYTHON_VERSION: "3.4.x" # currently 3.4.3
17-
PYTHON_ARCH: "64"
18-
197
- PYTHON: "C:\\Python35"
208
PYTHON_VERSION: "3.5.x" # currently 3.5.1
219
PYTHON_ARCH: "32"
@@ -54,7 +42,7 @@ install:
5442
- pip install pytest pytest-sugar
5543
- pip install -r build_requirements.txt
5644

57-
build: false
45+
build: off
5846
cache:
5947
- '%LOCALAPPDATA%\pip\Cache'
6048

doc/source/PrettyFormat.rst

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
66
.. py:module:: logwrap
77
.. py:currentmodule:: logwrap
88
9-
.. py:function:: pretty_repr(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, py2_str=False, )
9+
.. py:function:: pretty_repr(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, )
1010
1111
Make human readable repr of object.
1212

1313
:param src: object to process
14-
:type src: typing.Union[
15-
typing.AnyStr, int, typing.Iterable, object
16-
]
14+
:type src: typing.Any
1715
:param indent: start indentation, all next levels is +indent_step
1816
:type indent: int
1917
:param no_indent_start: do not indent open bracket and simple parameters
@@ -22,22 +20,18 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
2220
:type max_indent: int
2321
:param indent_step: step for the next indentation level
2422
:type indent_step: int
25-
:param py2_str: use Python 2.x compatible strings instead of unicode
26-
:type py2_str: bool
2723
:return: formatted string
2824
:rtype: str
2925

3026

31-
.. py:function:: pretty_str(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, py2_str=False, )
27+
.. py:function:: pretty_str(src, indent=0, no_indent_start=False, max_indent=20, indent_step=4, )
3228
3329
Make human readable str of object.
3430

3531
.. versionadded:: 1.1.0
3632

3733
:param src: object to process
38-
:type src: typing.Union[
39-
typing.AnyStr, int, typing.Iterable, object
40-
]
34+
:type src: typing.Any
4135
:param indent: start indentation, all next levels is +indent_step
4236
:type indent: int
4337
:param no_indent_start: do not indent open bracket and simple parameters
@@ -46,8 +40,6 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
4640
:type max_indent: int
4741
:param indent_step: step for the next indentation level
4842
:type indent_step: int
49-
:param py2_str: use Python 2.x compatible strings instead of unicode
50-
:type py2_str: bool
5143
:return: formatted string
5244
:rtype: str
5345

@@ -59,14 +51,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
5951
.. versionadded:: 1.0.2
6052
.. versionchanged:: 3.0.1
6153

62-
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
54+
.. py:method:: __init__(max_indent=20, indent_step=4, )
6355
6456
:param max_indent: maximal indent before classic repr() call
6557
:type max_indent: int
6658
:param indent_step: step for the next indentation level
6759
:type indent_step: int
68-
:param py2_str: use Python 2.x compatible strings instead of unicode
69-
:type py2_str: bool
7060

7161
.. note:: Attributes is read-only
7262

@@ -89,9 +79,7 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
8979
Make human readable representation of object.
9080

9181
:param src: object to process
92-
:type src: typing.Union[
93-
typing.AnyStr, int, typing.Iterable, object
94-
]
82+
:type src: typing.Any
9583
:param indent: start indentation
9684
:type indent: int
9785
:param no_indent_start:
@@ -105,9 +93,7 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
10593
Make human readable representation of object. The main entry point.
10694

10795
:param src: object to process
108-
:type src: typing.Union[
109-
typing.AnyStr, int, typing.Iterable, object
110-
]
96+
:type src: typing.Any
11197
:param indent: start indentation
11298
:type indent: int
11399
:param no_indent_start:
@@ -124,14 +110,12 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
124110
.. versionadded:: 3.0.0
125111
.. versionchanged:: 3.0.1
126112

127-
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
113+
.. py:method:: __init__(max_indent=20, indent_step=4, )
128114
129115
:param max_indent: maximal indent before classic repr() call
130116
:type max_indent: int
131117
:param indent_step: step for the next indentation level
132118
:type indent_step: int
133-
:param py2_str: use Python 2.x compatible strings instead of unicode
134-
:type py2_str: bool
135119

136120

137121
.. py:class:: PrettyStr(PrettyFormat)
@@ -141,11 +125,9 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
141125
.. versionadded:: 3.0.0
142126
.. versionchanged:: 3.0.1
143127

144-
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )
128+
.. py:method:: __init__(max_indent=20, indent_step=4, )
145129
146130
:param max_indent: maximal indent before classic repr() call
147131
:type max_indent: int
148132
:param indent_step: step for the next indentation level
149133
:type indent_step: int
150-
:param py2_str: use Python 2.x compatible strings instead of unicode
151-
:type py2_str: bool

logwrap/__init__.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,14 @@
2222
later it has been reworked and extended for support of special cases.
2323
"""
2424

25-
from __future__ import absolute_import
26-
27-
import sys
28-
2925
from ._repr_utils import (
3026
PrettyFormat,
3127
PrettyRepr,
3228
PrettyStr,
3329
pretty_repr,
3430
pretty_str
3531
)
36-
from ._log_wrap_shared import BoundParameter, bind_args_kwargs
37-
38-
PY3 = sys.version_info[:2] > (3, 0) # type: bool
39-
40-
# pylint: disable=no-name-in-module
41-
if PY3: # pragma: no cover
42-
from ._log_wrap3 import logwrap, LogWrap
43-
else: # pragma: no cover
44-
from ._log_wrap2 import logwrap, LogWrap
45-
# pylint: enable=no-name-in-module
32+
from ._log_wrap import logwrap, LogWrap, BoundParameter, bind_args_kwargs
4633

4734
__all__ = (
4835
'LogWrap',
@@ -56,7 +43,7 @@
5643
'bind_args_kwargs'
5744
)
5845

59-
__version__ = '4.0.1'
46+
__version__ = '5.0.0'
6047
__author__ = "Alexey Stepanov"
6148
__author_email__ = 'penguinolog@gmail.com'
6249
__maintainers__ = {

logwrap/_class_decorator.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@
1616

1717
"""Base class for decorators."""
1818

19-
from __future__ import absolute_import
20-
from __future__ import print_function
21-
2219
import abc
2320
import functools
24-
import typing # noqa # pylint: disable=unused-import
25-
26-
import six
21+
import typing
2722

2823

29-
class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):
24+
class BaseDecorator(metaclass=abc.ABCMeta):
3025
"""Base class for decorators.
3126
3227
Implements wrapping and __call__, wrapper getter is abstract.
@@ -69,27 +64,25 @@ class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):
6964

7065
def __init__(
7166
self,
72-
func=None # type: typing.Optional[typing.Callable]
73-
): # type: (...) -> None
67+
func: typing.Optional[typing.Callable] = None
68+
) -> None:
7469
"""Decorator.
7570
7671
:param func: function to wrap
7772
:type func: typing.Optional[typing.Callable]
7873
"""
74+
# noinspection PyArgumentList
75+
super(BaseDecorator, self).__init__()
7976
# pylint: disable=assigning-non-slot
8077
self.__func = func # type: typing.Optional[typing.Callable]
8178
if self.__func is not None:
8279
functools.update_wrapper(self, self.__func)
83-
if not six.PY3: # pragma: no cover
84-
self.__wrapped__ = self.__func # type: typing.Callable
8580
# pylint: enable=assigning-non-slot
86-
# noinspection PyArgumentList
87-
super(BaseDecorator, self).__init__()
8881

8982
@property
9083
def _func(
9184
self
92-
): # type: () -> typing.Optional[typing.Callable]
85+
) -> typing.Optional[typing.Callable]:
9386
"""Get wrapped function.
9487
9588
:rtype: typing.Optional[typing.Callable]
@@ -99,8 +92,8 @@ def _func(
9992
@abc.abstractmethod
10093
def _get_function_wrapper(
10194
self,
102-
func # type: typing.Callable
103-
): # type: (...) -> typing.Callable
95+
func: typing.Callable
96+
) -> typing.Callable:
10497
"""Here should be constructed and returned real decorator.
10598
10699
:param func: Wrapped function
@@ -111,18 +104,23 @@ def _get_function_wrapper(
111104

112105
def __call__(
113106
self,
114-
*args, # type: typing.Any
115-
**kwargs # type: typing.Any
116-
): # type: (...) -> typing.Any
107+
*args: typing.Union[typing.Tuple, typing.Callable],
108+
**kwargs: typing.Dict
109+
) -> typing.Any:
117110
"""Main decorator getter."""
118-
args = list(args)
119-
wrapped = self.__func or args.pop(0)
111+
l_args = list(args)
112+
113+
if self._func:
114+
wrapped = self._func # type: typing.Callable
115+
else:
116+
wrapped = l_args.pop(0) # type: ignore
117+
120118
wrapper = self._get_function_wrapper(wrapped)
121119
if self.__func:
122-
return wrapper(*args, **kwargs)
120+
return wrapper(*l_args, **kwargs)
123121
return wrapper
124122

125-
def __repr__(self):
123+
def __repr__(self) -> str:
126124
"""For debug purposes."""
127125
return "<{cls}({func!r}) at 0x{id:X}>".format(
128126
cls=self.__class__.__name__,

logwrap/_class_decorator.pyi

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)