Skip to content
Merged
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
7 changes: 3 additions & 4 deletions logwrap/_class_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

import abc
import functools
import sys
import typing # noqa # pylint: disable=unused-import

PY3 = sys.version_info[:2] > (3, 0) # type: bool
import six


class BaseDecorator(object):
class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):
"""Base class for decorators.

Implements wrapping and __call__, wrapper getter is abstract.
Expand Down Expand Up @@ -81,7 +80,7 @@ def __init__(
self.__func = func # type: typing.Optional[typing.Callable]
if self.__func is not None:
functools.update_wrapper(self, self.__func)
if not PY3: # pragma: no cover
if not six.PY3: # pragma: no cover
self.__wrapped__ = self.__func # type: typing.Callable
# pylint: enable=assigning-non-slot
# noinspection PyArgumentList
Expand Down
2 changes: 1 addition & 1 deletion logwrap/_class_decorator.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import typing

PY3: bool

class BaseDecorator:
class BaseDecorator(object, metaclass=abc.ABCMeta):
def __init__(self, func: typing.Optional[typing.Callable]=...) -> None: ...

@property
Expand Down
22 changes: 20 additions & 2 deletions logwrap/_log_wrap2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,26 @@ class LogWrap(_log_wrap_shared.BaseLogWrap):

def _get_function_wrapper(self, func: typing.Callable) -> typing.Callable: ...


@typing.overload
def logwrap(
func: None=...,
log: logging.Logger=...,
log_level: int=...,
exc_level: int=...,
max_indent: int=...,
spec: typing.Optional[typing.Callable]=...,
blacklisted_names: typing.Optional[typing.List[str]]=...,
blacklisted_exceptions: typing.Optional[typing.List[typing.Type[Exception]]]=...,
log_call_args: bool=...,
log_call_args_on_exc: bool=...,
log_result_obj: bool=...
) -> LogWrap: ...


@typing.overload
def logwrap(
func: typing.Optional[typing.Callable]=None,
func: typing.Callable=...,
log: logging.Logger=...,
log_level: int=...,
exc_level: int=...,
Expand All @@ -35,4 +53,4 @@ def logwrap(
log_call_args: bool=...,
log_call_args_on_exc: bool=...,
log_result_obj: bool=...
) -> typing.Union[LogWrap, typing.Callable]: ...
) -> typing.Callable: ...
25 changes: 22 additions & 3 deletions logwrap/_log_wrap3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LogWrap(_log_wrap_shared.BaseLogWrap):

def __init__(
self,
func: typing.Optional[typing.Callable]=None,
func: typing.Optional[typing.Callable]=...,
*,
log: logging.Logger=...,
log_level: int=...,
Expand All @@ -24,8 +24,27 @@ class LogWrap(_log_wrap_shared.BaseLogWrap):

def _get_function_wrapper(self, func: typing.Callable) -> typing.Callable: ...


@typing.overload
def logwrap(
func: None=...,
*,
log: logging.Logger=...,
log_level: int=...,
exc_level: int=...,
max_indent: int=...,
spec: typing.Optional[typing.Callable]=...,
blacklisted_names: typing.Optional[typing.List[str]]=...,
blacklisted_exceptions: typing.Optional[typing.List[typing.Type[Exception]]]=...,
log_call_args: bool=...,
log_call_args_on_exc: bool=...,
log_result_obj: bool=...
) -> LogWrap: ...


@typing.overload
def logwrap(
func: typing.Optional[typing.Callable]=None,
func: typing.Callable=...,
*,
log: logging.Logger=...,
log_level: int=...,
Expand All @@ -37,4 +56,4 @@ def logwrap(
log_call_args: bool=...,
log_call_args_on_exc: bool=...,
log_result_obj: bool=...
) -> typing.Union[LogWrap, typing.Callable]: ...
) -> typing.Callable: ...
13 changes: 7 additions & 6 deletions logwrap/_log_wrap_shared.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import abc
import enum
import inspect
import logging
Expand Down Expand Up @@ -33,7 +34,7 @@ class BoundParameter(object):
KEYWORD_ONLY = Parameter.KEYWORD_ONLY
VAR_KEYWORD = Parameter.VAR_KEYWORD

empty = Parameter.empty # type: typing.Type
empty: typing.Type = Parameter.empty

def __init__(
self,
Expand Down Expand Up @@ -62,12 +63,12 @@ class BoundParameter(object):

def bind_args_kwargs(
sig: Signature,
*args,
**kwargs
*args: typing.Tuple,
**kwargs: typing.Dict
) -> typing.Iterator[BoundParameter]: ...


class BaseLogWrap(_class_decorator.BaseDecorator):
class BaseLogWrap(_class_decorator.BaseDecorator, metaclass=abc.ABCMeta):
def __init__(
self,
func: typing.Optional[typing.Callable]=None,
Expand Down Expand Up @@ -134,8 +135,8 @@ class BaseLogWrap(_class_decorator.BaseDecorator):
@staticmethod
def _bind_args_kwargs(
sig: Signature,
*args,
**kwargs
*args: typing.Tuple,
**kwargs: typing.Dict
) -> typing.Iterator[BoundParameter]: ...

def pre_process_param(
Expand Down
7 changes: 3 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
[metadata]
name = logwrap
project_urls =
Bug Tracker = https://github.com/python-useful-helpers/logwrap/issues
Documentation = https://logwrap.readthedocs.io/

long_description = file: README.rst

[options]
zip_safe = False
packages = find:
setup_requires =
setuptools > 20.2

python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*

[bdist_wheel]
# This flag says that the code is written to work on both Python 2 and Python
Expand Down
10 changes: 10 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ def get_simple_vars_from_src(src):
long_description=long_description,
classifiers=classifiers,
keywords=keywords,
python_requires='>=2.7.5,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*',
# While setuptools cannot deal with pre-installed incompatible versions,
# setting a lower bound is not harmful - it makes error messages cleaner. DO
# NOT set an upper bound on setuptools, as that will lead to uninstallable
# situations as progressive releases of projects are done.
# Blacklist setuptools 34.0.0-34.3.2 due to https://github.com/pypa/setuptools/issues/951
# Blacklist setuptools 36.2.0 due to https://github.com/pypa/setuptools/issues/1086
setup_requires="setuptools >= 21.0.0,!=24.0.0,"
"!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,"
"!=36.2.0",
extras_require={
':python_version == "2.7"': [
'funcsigs>=1.0',
Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ commands = pip install ./ -vvv -U

[testenv:pylint]
deps =
pylint
pylint<2
-r{toxinidir}/CI_REQUIREMENTS.txt
commands = pylint logwrap

Expand Down Expand Up @@ -118,3 +118,9 @@ deps =
commands =
pipenv install -r {toxinidir}/build_requirements.txt --skip-lock
pipenv graph

[testenv:mypy]
deps =
mypy>=0.620
-r{toxinidir}/CI_REQUIREMENTS.txt
commands = mypy --strict logwrap