Skip to content

Commit

Permalink
Merge pull request #46 from MichalTHEDUDE/feature/NewStyleClasses
Browse files Browse the repository at this point in the history
Moving to new style classes (object inheritance) - Issue #44
  • Loading branch information
hpk42 authored Feb 16, 2017
2 parents 21771da + 0759210 commit cf059aa
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 71 deletions.
6 changes: 3 additions & 3 deletions docs/examples/firstexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hookimpl = pluggy.HookimplMarker("myproject")


class MySpec:
class MySpec(object):
"""A hook specification namespace.
"""
@hookspec
Expand All @@ -13,7 +13,7 @@ def myhook(self, arg1, arg2):
"""


class Plugin_1:
class Plugin_1(object):
"""A hook implementation namespace.
"""
@hookimpl
Expand All @@ -22,7 +22,7 @@ def myhook(self, arg1, arg2):
return arg1 + arg2


class Plugin_2:
class Plugin_2(object):
"""A 2nd hook implementation namespace.
"""
@hookimpl
Expand Down
18 changes: 9 additions & 9 deletions pluggy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
_py3 = sys.version_info > (3, 0)


class HookspecMarker:
class HookspecMarker(object):
""" Decorator helper class for marking functions as hook specifications.
You can instantiate it with a project_name to get a decorator.
Expand Down Expand Up @@ -47,7 +47,7 @@ def setattr_hookspec_opts(func):
return setattr_hookspec_opts


class HookimplMarker:
class HookimplMarker(object):
""" Decorator helper class for marking functions as hook implementations.
You can instantiate with a project_name to get a decorator.
Expand Down Expand Up @@ -101,7 +101,7 @@ def normalize_hookimpl_opts(opts):
opts.setdefault("optionalhook", False)


class _TagTracer:
class _TagTracer(object):
def __init__(self):
self._tag2proc = {}
self.writer = None
Expand Down Expand Up @@ -148,7 +148,7 @@ def setprocessor(self, tags, processor):
self._tag2proc[tags] = processor


class _TagTracerSub:
class _TagTracerSub(object):
def __init__(self, root, tags):
self.root = root
self.tags = tags
Expand Down Expand Up @@ -188,7 +188,7 @@ def _wrapped_call(wrap_controller, func):
return call_outcome.get_result()


class _CallOutcome:
class _CallOutcome(object):
""" Outcome of a function call, either an exception or a proper result.
Calling the ``get_result`` method will return the result or reraise
the exception raised when the function was called. """
Expand Down Expand Up @@ -221,7 +221,7 @@ def _reraise(cls, val, tb):
""")


class _TracedHookExecution:
class _TracedHookExecution(object):
def __init__(self, pluginmanager, before, after):
self.pluginmanager = pluginmanager
self.before = before
Expand Down Expand Up @@ -517,7 +517,7 @@ def subset_hook_caller(self, name, remove_plugins):
return orig


class _MultiCall:
class _MultiCall(object):
""" execute a call into multiple python functions/methods. """

# XXX note that the __multicall__ argument is supported only
Expand Down Expand Up @@ -611,7 +611,7 @@ def varnames(func):
return tuple(args)


class _HookRelay:
class _HookRelay(object):
""" hook holder object for performing 1:N hook calls where N is the number
of registered plugins.
Expand Down Expand Up @@ -715,7 +715,7 @@ def _maybe_apply_history(self, method):
proc(res[0])


class HookImpl:
class HookImpl(object):
def __init__(self, plugin, plugin_name, function, hook_impl_opts):
self.function = function
self.argnames = varnames(self.function)
Expand Down
2 changes: 1 addition & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def he_pm(request, pm):
from pluggy import HookspecMarker
hookspec = HookspecMarker("example")

class Hooks:
class Hooks(object):
@hookspec
def he_method1(self, arg):
return arg + 1
Expand Down
8 changes: 4 additions & 4 deletions testing/test_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def parse_hookimpl_opts(self, module_or_class, name):
opts = {}
return opts

class Plugin:
class Plugin(object):
def x1meth(self):
pass

@hookimpl(hookwrapper=True, tryfirst=True)
def x1meth2(self):
pass

class Spec:
class Spec(object):
@hookspec
def x1meth(self):
pass
Expand All @@ -48,11 +48,11 @@ def test_plugin_getattr_raises_errors():
"""Pluggy must be able to handle plugins which raise weird exceptions
when getattr() gets called (#11).
"""
class DontTouchMe:
class DontTouchMe(object):
def __getattr__(self, x):
raise Exception('cant touch me')

class Module:
class Module(object):
pass

module = Module()
Expand Down
6 changes: 3 additions & 3 deletions testing/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def test_varnames():
def f(x):
i = 3 # noqa

class A:
class A(object):
def f(self, y):
pass

Expand All @@ -26,11 +26,11 @@ def f(x, y=3):


def test_varnames_class():
class C:
class C(object):
def __init__(self, x):
pass

class D:
class D(object):
pass

class E(object):
Expand Down
14 changes: 7 additions & 7 deletions testing/test_hookrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def test_happypath(pm):
class Api:
class Api(object):
@hookspec
def hello(self, arg):
"api hook 1"
Expand All @@ -17,7 +17,7 @@ def hello(self, arg):
assert hasattr(hook, 'hello')
assert repr(hook.hello).find("hello") != -1

class Plugin:
class Plugin(object):
@hookimpl
def hello(self, arg):
return arg + 1
Expand All @@ -32,14 +32,14 @@ def hello(self, arg):


def test_argmismatch(pm):
class Api:
class Api(object):
@hookspec
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)

class Plugin:
class Plugin(object):
@hookimpl
def hello(self, argwrong):
pass
Expand All @@ -51,7 +51,7 @@ def hello(self, argwrong):


def test_only_kwargs(pm):
class Api:
class Api(object):
@hookspec
def hello(self, arg):
"api hook 1"
Expand All @@ -61,14 +61,14 @@ def hello(self, arg):


def test_firstresult_definition(pm):
class Api:
class Api(object):
@hookspec(firstresult=True)
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)

class Plugin:
class Plugin(object):
@hookimpl
def hello(self, arg):
return arg + 1
Expand Down
26 changes: 13 additions & 13 deletions testing/test_method_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@pytest.fixture
def hc(pm):
class Hooks:
class Hooks(object):
@hookspec
def he_method1(self, arg):
pass
Expand Down Expand Up @@ -149,7 +149,7 @@ def he_method2():


def test_hookspec(pm):
class HookSpec:
class HookSpec(object):
@hookspec()
def he_myhook1(arg1):
pass
Expand Down Expand Up @@ -181,14 +181,14 @@ def he_myhook1(arg1):


def test_decorator_functional(pm):
class HookSpec:
class HookSpec(object):
@hookspec(firstresult=True)
def he_myhook(self, arg1):
""" add to arg1 """

pm.add_hookspecs(HookSpec)

class Plugin:
class Plugin(object):
@hookimpl()
def he_myhook(self, arg1):
return arg1 + 1
Expand All @@ -204,12 +204,12 @@ def test_load_setuptools_instantiation(monkeypatch, pm):
def my_iter(name):
assert name == "hello"

class EntryPoint:
class EntryPoint(object):
name = "myname"
dist = None

def load(self):
class PseudoPlugin:
class PseudoPlugin(object):
x = 42
return PseudoPlugin()

Expand All @@ -235,12 +235,12 @@ def test_load_setuptools_not_installed(monkeypatch, pm):
def test_add_tracefuncs(he_pm):
l = []

class api1:
class api1(object):
@hookimpl
def he_method1(self):
l.append("he_method1-api1")

class api2:
class api2(object):
@hookimpl
def he_method1(self):
l.append("he_method1-api2")
Expand Down Expand Up @@ -274,12 +274,12 @@ def after(outcome, hook_name, hook_impls, kwargs):
def test_hook_tracing(he_pm):
saveindent = []

class api1:
class api1(object):
@hookimpl
def he_method1(self):
saveindent.append(he_pm.trace.root.indent)

class api2:
class api2(object):
@hookimpl
def he_method1(self):
saveindent.append(he_pm.trace.root.indent)
Expand Down Expand Up @@ -311,14 +311,14 @@ def he_method1(self):
def test_prefix_hookimpl():
pm = PluginManager(hookspec.project_name, "hello_")

class HookSpec:
class HookSpec(object):
@hookspec
def hello_myhook(self, arg1):
""" add to arg1 """

pm.add_hookspecs(HookSpec)

class Plugin:
class Plugin(object):
def hello_myhook(self, arg1):
return arg1 + 1

Expand All @@ -331,7 +331,7 @@ def hello_myhook(self, arg1):
def test_prefix_hookimpl_dontmatch_module():
pm = PluginManager(hookspec.project_name, "hello_")

class BadPlugin:
class BadPlugin(object):
hello_module = __import__('email')

pm.register(BadPlugin())
Expand Down
6 changes: 3 additions & 3 deletions testing/test_multicall.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def MC(methods, kwargs, firstresult=False):


def test_call_passing():
class P1:
class P1(object):
@hookimpl
def m(self, __multicall__, x):
assert len(__multicall__.results) == 1
assert not __multicall__.hook_impls
return 17

class P2:
class P2(object):
@hookimpl
def m(self, __multicall__, x):
assert __multicall__.results == []
Expand All @@ -55,7 +55,7 @@ def test_keyword_args():
def f(x):
return x + 1

class A:
class A(object):
@hookimpl
def f(self, x, y):
return x + y
Expand Down
Loading

0 comments on commit cf059aa

Please sign in to comment.