Skip to content

Commit 6b344fb

Browse files
Merge pull request #319 from RonnyPfannschmidt/pre-commit-update
introduce pyupgrade and update black
2 parents 98be76f + 71f2d6b commit 6b344fb

File tree

7 files changed

+55
-62
lines changed

7 files changed

+55
-62
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: 19.10b0
3+
rev: 21.7b0
44
hooks:
55
- id: black
66
args: [--safe, --quiet]
77
- repo: https://github.com/asottile/blacken-docs
8-
rev: v0.5.0
8+
rev: v1.10.0
99
hooks:
1010
- id: blacken-docs
11-
additional_dependencies: [black==19.10b0]
11+
additional_dependencies: [black==21.7b0]
1212
- repo: https://github.com/pre-commit/pre-commit-hooks
1313
rev: v2.1.0
1414
hooks:
@@ -24,6 +24,11 @@ repos:
2424
language: python
2525
additional_dependencies: [pygments, restructuredtext_lint]
2626
- repo: https://github.com/pre-commit/pygrep-hooks
27-
rev: v1.3.0
27+
rev: v1.9.0
2828
hooks:
2929
- id: rst-backticks
30+
- repo: https://github.com/asottile/pyupgrade
31+
rev: v2.23.3
32+
hooks:
33+
- id: pyupgrade
34+
args: [--py36-plus]

README.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@ A definitive example
1919
2020
2121
class MySpec:
22-
"""A hook specification namespace.
23-
"""
22+
"""A hook specification namespace."""
2423
2524
@hookspec
2625
def myhook(self, arg1, arg2):
27-
"""My special little hook that you can customize.
28-
"""
26+
"""My special little hook that you can customize."""
2927
3028
3129
class Plugin_1:
32-
"""A hook implementation namespace.
33-
"""
30+
"""A hook implementation namespace."""
3431
3532
@hookimpl
3633
def myhook(self, arg1, arg2):
@@ -39,8 +36,7 @@ A definitive example
3936
4037
4138
class Plugin_2:
42-
"""A 2nd hook implementation namespace.
43-
"""
39+
"""A 2nd hook implementation namespace."""
4440
4541
@hookimpl
4642
def myhook(self, arg1, arg2):

docs/index.rst

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,15 @@ will be executed *first* or *last* respectively in the hook call loop:
319319
320320
@hookimpl(trylast=True)
321321
def setup_project(config, args):
322-
"""Default implementation.
323-
"""
322+
"""Default implementation."""
324323
if args:
325324
config.process_args(args)
326325
327326
return config
328327
329328
330329
class SomeOtherPlugin:
331-
"""Some other plugin defining the same hook.
332-
"""
330+
"""Some other plugin defining the same hook."""
333331
334332
@hookimpl(tryfirst=True)
335333
def setup_project(self, config, args):
@@ -696,24 +694,21 @@ assertion should not error:
696694
class Plugin1:
697695
@hookimpl
698696
def myhook(self, args):
699-
"""Default implementation.
700-
"""
697+
"""Default implementation."""
701698
return 1
702699
703700
704701
class Plugin2:
705702
@hookimpl
706703
def myhook(self, args):
707-
"""Default implementation.
708-
"""
704+
"""Default implementation."""
709705
return 2
710706
711707
712708
class Plugin3:
713709
@hookimpl
714710
def myhook(self, args):
715-
"""Default implementation.
716-
"""
711+
"""Default implementation."""
717712
return 3
718713
719714

src/pluggy/_hooks.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class HookspecMarker:
10-
""" Decorator helper class for marking functions as hook specifications.
10+
"""Decorator helper class for marking functions as hook specifications.
1111
1212
You can instantiate it with a project_name to get a decorator.
1313
Calling :py:meth:`.PluginManager.add_hookspecs` later will discover all marked functions
@@ -20,7 +20,7 @@ def __init__(self, project_name):
2020
def __call__(
2121
self, function=None, firstresult=False, historic=False, warn_on_impl=None
2222
):
23-
""" if passed a function, directly sets attributes on the function
23+
"""if passed a function, directly sets attributes on the function
2424
which will make it discoverable to :py:meth:`.PluginManager.add_hookspecs`.
2525
If passed no function, returns a decorator which can be applied to a function
2626
later using the attributes supplied.
@@ -55,7 +55,7 @@ def setattr_hookspec_opts(func):
5555

5656

5757
class HookimplMarker:
58-
""" Decorator helper class for marking functions as hook implementations.
58+
"""Decorator helper class for marking functions as hook implementations.
5959
6060
You can instantiate with a ``project_name`` to get a decorator.
6161
Calling :py:meth:`.PluginManager.register` later will discover all marked functions
@@ -75,7 +75,7 @@ def __call__(
7575
specname=None,
7676
):
7777

78-
""" if passed a function, directly sets attributes on the function
78+
"""if passed a function, directly sets attributes on the function
7979
which will make it discoverable to :py:meth:`.PluginManager.register`.
8080
If passed no function, returns a decorator which can be applied to a
8181
function later using the attributes supplied.
@@ -175,7 +175,7 @@ def varnames(func):
175175

176176

177177
class _HookRelay:
178-
""" hook holder object for performing 1:N hook calls where N is the number
178+
"""hook holder object for performing 1:N hook calls where N is the number
179179
of registered plugins.
180180
181181
"""
@@ -221,8 +221,7 @@ def get_hookimpls(self):
221221
return self._nonwrappers + self._wrappers
222222

223223
def _add_hookimpl(self, hookimpl):
224-
"""Add an implementation to the callback chain.
225-
"""
224+
"""Add an implementation to the callback chain."""
226225
if hookimpl.hookwrapper:
227226
methods = self._wrappers
228227
else:
@@ -282,8 +281,8 @@ def call_historic(self, result_callback=None, kwargs=None):
282281
result_callback(x)
283282

284283
def call_extra(self, methods, kwargs):
285-
""" Call the hook with some additional temporarily participating
286-
methods using the specified ``kwargs`` as call parameters. """
284+
"""Call the hook with some additional temporarily participating
285+
methods using the specified ``kwargs`` as call parameters."""
287286
old = list(self._nonwrappers), list(self._wrappers)
288287
for method in methods:
289288
opts = dict(hookwrapper=False, trylast=False, tryfirst=False)
@@ -295,8 +294,7 @@ def call_extra(self, methods, kwargs):
295294
self._nonwrappers, self._wrappers = old
296295

297296
def _maybe_apply_history(self, method):
298-
"""Apply call history to a new hookimpl if it is marked as historic.
299-
"""
297+
"""Apply call history to a new hookimpl if it is marked as historic."""
300298
if self.is_historic():
301299
for kwargs, result_callback in self._call_history:
302300
res = self._hookexec(self.name, [method], kwargs, False)

src/pluggy/_manager.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _warn_for_function(warning, function):
2222

2323

2424
class PluginValidationError(Exception):
25-
""" plugin failed validation.
25+
"""plugin failed validation.
2626
2727
:param object plugin: the plugin which failed validation,
2828
may be a module or an arbitrary object.
@@ -51,7 +51,7 @@ def __dir__(self):
5151

5252

5353
class PluginManager:
54-
""" Core :py:class:`.PluginManager` class which manages registration
54+
"""Core :py:class:`.PluginManager` class which manages registration
5555
of plugin objects and 1:N hook calling.
5656
5757
You can register new hooks by calling :py:meth:`add_hookspecs(module_or_class)
@@ -80,9 +80,9 @@ def _hookexec(self, hook_name, methods, kwargs, firstresult):
8080
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
8181

8282
def register(self, plugin, name=None):
83-
""" Register a plugin and return its canonical name or ``None`` if the name
83+
"""Register a plugin and return its canonical name or ``None`` if the name
8484
is blocked from registering. Raise a :py:class:`ValueError` if the plugin
85-
is already registered. """
85+
is already registered."""
8686
plugin_name = name or self.get_canonical_name(plugin)
8787

8888
if plugin_name in self._name2plugin or plugin in self._plugin2hookcallers:
@@ -131,8 +131,8 @@ def parse_hookimpl_opts(self, plugin, name):
131131
return res
132132

133133
def unregister(self, plugin=None, name=None):
134-
""" unregister a plugin object and all its contained hook implementations
135-
from internal data structures. """
134+
"""unregister a plugin object and all its contained hook implementations
135+
from internal data structures."""
136136
if name is None:
137137
assert plugin is not None, "one of name or plugin needs to be specified"
138138
name = self.get_name(plugin)
@@ -150,17 +150,17 @@ def unregister(self, plugin=None, name=None):
150150
return plugin
151151

152152
def set_blocked(self, name):
153-
""" block registrations of the given name, unregister if already registered. """
153+
"""block registrations of the given name, unregister if already registered."""
154154
self.unregister(name=name)
155155
self._name2plugin[name] = None
156156

157157
def is_blocked(self, name):
158-
""" return ``True`` if the given plugin name is blocked. """
158+
"""return ``True`` if the given plugin name is blocked."""
159159
return name in self._name2plugin and self._name2plugin[name] is None
160160

161161
def add_hookspecs(self, module_or_class):
162-
""" add new hook specifications defined in the given ``module_or_class``.
163-
Functions are recognized if they have been decorated accordingly. """
162+
"""add new hook specifications defined in the given ``module_or_class``.
163+
Functions are recognized if they have been decorated accordingly."""
164164
names = []
165165
for name in dir(module_or_class):
166166
spec_opts = self.parse_hookspec_opts(module_or_class, name)
@@ -186,31 +186,31 @@ def parse_hookspec_opts(self, module_or_class, name):
186186
return getattr(method, self.project_name + "_spec", None)
187187

188188
def get_plugins(self):
189-
""" return the set of registered plugins. """
189+
"""return the set of registered plugins."""
190190
return set(self._plugin2hookcallers)
191191

192192
def is_registered(self, plugin):
193-
""" Return ``True`` if the plugin is already registered. """
193+
"""Return ``True`` if the plugin is already registered."""
194194
return plugin in self._plugin2hookcallers
195195

196196
def get_canonical_name(self, plugin):
197-
""" Return canonical name for a plugin object. Note that a plugin
197+
"""Return canonical name for a plugin object. Note that a plugin
198198
may be registered under a different name which was specified
199199
by the caller of :py:meth:`register(plugin, name) <.PluginManager.register>`.
200200
To obtain the name of an registered plugin use :py:meth:`get_name(plugin)
201201
<.PluginManager.get_name>` instead."""
202202
return getattr(plugin, "__name__", None) or str(id(plugin))
203203

204204
def get_plugin(self, name):
205-
""" Return a plugin or ``None`` for the given name. """
205+
"""Return a plugin or ``None`` for the given name."""
206206
return self._name2plugin.get(name)
207207

208208
def has_plugin(self, name):
209-
""" Return ``True`` if a plugin with the given name is registered. """
209+
"""Return ``True`` if a plugin with the given name is registered."""
210210
return self.get_plugin(name) is not None
211211

212212
def get_name(self, plugin):
213-
""" Return name for registered plugin or ``None`` if not registered. """
213+
"""Return name for registered plugin or ``None`` if not registered."""
214214
for name, val in self._name2plugin.items():
215215
if plugin == val:
216216
return name
@@ -251,7 +251,7 @@ def _verify_hook(self, hook, hookimpl):
251251
)
252252

253253
def check_pending(self):
254-
""" Verify that all hooks which have not been verified against
254+
"""Verify that all hooks which have not been verified against
255255
a hook specification are optional, otherwise raise :py:class:`.PluginValidationError`."""
256256
for name in self.hook.__dict__:
257257
if name[0] != "_":
@@ -266,7 +266,7 @@ def check_pending(self):
266266
)
267267

268268
def load_setuptools_entrypoints(self, group, name=None):
269-
""" Load modules from querying the specified setuptools ``group``.
269+
"""Load modules from querying the specified setuptools ``group``.
270270
271271
:param str group: entry point group to load plugins
272272
:param str name: if given, loads only plugins with the given ``name``.
@@ -291,20 +291,20 @@ def load_setuptools_entrypoints(self, group, name=None):
291291
return count
292292

293293
def list_plugin_distinfo(self):
294-
""" return list of distinfo/plugin tuples for all setuptools registered
295-
plugins. """
294+
"""return list of distinfo/plugin tuples for all setuptools registered
295+
plugins."""
296296
return list(self._plugin_distinfo)
297297

298298
def list_name_plugin(self):
299-
""" return list of name/plugin pairs. """
299+
"""return list of name/plugin pairs."""
300300
return list(self._name2plugin.items())
301301

302302
def get_hookcallers(self, plugin):
303-
""" get all hook callers for the specified plugin. """
303+
"""get all hook callers for the specified plugin."""
304304
return self._plugin2hookcallers.get(plugin)
305305

306306
def add_hookcall_monitoring(self, before, after):
307-
""" add before/after tracing functions for all hooks
307+
"""add before/after tracing functions for all hooks
308308
and return an undo function which, when called,
309309
will remove the added tracers.
310310
@@ -334,7 +334,7 @@ def undo():
334334
return undo
335335

336336
def enable_tracing(self):
337-
""" enable tracing of hook calls and return an undo function. """
337+
"""enable tracing of hook calls and return an undo function."""
338338
hooktrace = self.trace.root.get("hook")
339339

340340
def before(hook_name, methods, kwargs):
@@ -349,9 +349,9 @@ def after(outcome, hook_name, methods, kwargs):
349349
return self.add_hookcall_monitoring(before, after)
350350

351351
def subset_hook_caller(self, name, remove_plugins):
352-
""" Return a new :py:class:`._hooks._HookCaller` instance for the named method
352+
"""Return a new :py:class:`._hooks._HookCaller` instance for the named method
353353
which manages calls to all registered plugins except the
354-
ones from remove_plugins. """
354+
ones from remove_plugins."""
355355
orig = getattr(self.hook, name)
356356
plugins_to_remove = [plug for plug in remove_plugins if hasattr(plug, name)]
357357
if plugins_to_remove:

src/pluggy/_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def _raise_wrapfail(wrap_controller, msg):
1313

1414

1515
class HookCallError(Exception):
16-
""" Hook was called wrongly. """
16+
"""Hook was called wrongly."""
1717

1818

1919
class _Result:

testing/test_invocations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ def hello(self, arg):
144144

145145

146146
def test_firstresult_force_result(pm):
147-
"""Verify forcing a result in a wrapper.
148-
"""
147+
"""Verify forcing a result in a wrapper."""
149148

150149
class Api:
151150
@hookspec(firstresult=True)

0 commit comments

Comments
 (0)