Skip to content

Commit 144b726

Browse files
author
Scott Sanderson
committed
BLD: Use Black.
1 parent 25074ae commit 144b726

14 files changed

+237
-240
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ repos:
2222
rev: v4.3.16
2323
hooks:
2424
- id: isort
25+
26+
- repo: https://github.com/ambv/black
27+
rev: stable
28+
hooks:
29+
- id: black
30+
language_version: python3.6

docs/conf.py

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
# -- Project information -----------------------------------------------------
2121

22-
project = 'interface'
23-
copyright = '2018, Scott Sanderson'
24-
author = 'Scott Sanderson'
22+
project = "interface"
23+
copyright = "2018, Scott Sanderson"
24+
author = "Scott Sanderson"
2525

2626
# The short X.Y version
27-
version = ''
27+
version = ""
2828
# The full version, including alpha/beta/rc tags
29-
release = '1.4.0'
29+
release = "1.4.0"
3030

3131

3232
# -- General configuration ---------------------------------------------------
@@ -39,26 +39,26 @@
3939
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
4040
# ones.
4141
extensions = [
42-
'sphinx.ext.autodoc',
43-
'sphinx.ext.doctest',
44-
'sphinx.ext.intersphinx',
45-
'sphinx.ext.todo',
46-
'sphinx.ext.viewcode',
47-
'sphinx.ext.napoleon',
48-
'sphinx.ext.autosummary',
42+
"sphinx.ext.autodoc",
43+
"sphinx.ext.doctest",
44+
"sphinx.ext.intersphinx",
45+
"sphinx.ext.todo",
46+
"sphinx.ext.viewcode",
47+
"sphinx.ext.napoleon",
48+
"sphinx.ext.autosummary",
4949
]
5050

5151
# Add any paths that contain templates here, relative to this directory.
52-
templates_path = ['_templates']
52+
templates_path = ["_templates"]
5353

5454
# The suffix(es) of source filenames.
5555
# You can specify multiple suffix as a list of string:
5656
#
5757
# source_suffix = ['.rst', '.md']
58-
source_suffix = '.rst'
58+
source_suffix = ".rst"
5959

6060
# The master toctree document.
61-
master_doc = 'index'
61+
master_doc = "index"
6262

6363
# The language for content autogenerated by Sphinx. Refer to documentation
6464
# for a list of supported languages.
@@ -70,18 +70,18 @@
7070
# List of patterns, relative to source directory, that match files and
7171
# directories to ignore when looking for source files.
7272
# This pattern also affects html_static_path and html_extra_path .
73-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7474

7575
# The name of the Pygments (syntax highlighting) style to use.
76-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7777

7878

7979
# -- Options for HTML output -------------------------------------------------
8080

8181
# The theme to use for HTML and HTML Help pages. See the documentation for
8282
# a list of builtin themes.
8383
#
84-
html_theme = 'sphinx_rtd_theme'
84+
html_theme = "sphinx_rtd_theme"
8585

8686
# Theme options are theme-specific and customize the look and feel of a theme
8787
# further. For a list of options available for each theme, see the
@@ -92,7 +92,7 @@
9292
# Add any paths that contain custom static files (such as style sheets) here,
9393
# relative to this directory. They are copied after the builtin static files,
9494
# so a file named "default.css" will overwrite the builtin "default.css".
95-
html_static_path = ['_static']
95+
html_static_path = ["_static"]
9696

9797
# Custom sidebar templates, must be a dictionary that maps document names
9898
# to template names.
@@ -108,7 +108,7 @@
108108
# -- Options for HTMLHelp output ---------------------------------------------
109109

110110
# Output file base name for HTML help builder.
111-
htmlhelp_basename = 'interfacedoc'
111+
htmlhelp_basename = "interfacedoc"
112112

113113

114114
# -- Options for LaTeX output ------------------------------------------------
@@ -117,15 +117,12 @@
117117
# The paper size ('letterpaper' or 'a4paper').
118118
#
119119
# 'papersize': 'letterpaper',
120-
121120
# The font size ('10pt', '11pt' or '12pt').
122121
#
123122
# 'pointsize': '10pt',
124-
125123
# Additional stuff for the LaTeX preamble.
126124
#
127125
# 'preamble': '',
128-
129126
# Latex figure (float) alignment
130127
#
131128
# 'figure_align': 'htbp',
@@ -135,19 +132,21 @@
135132
# (source start file, target name, title,
136133
# author, documentclass [howto, manual, or own class]).
137134
latex_documents = [
138-
(master_doc, 'interface.tex', 'interface Documentation',
139-
'Scott Sanderson', 'manual'),
135+
(
136+
master_doc,
137+
"interface.tex",
138+
"interface Documentation",
139+
"Scott Sanderson",
140+
"manual",
141+
),
140142
]
141143

142144

143145
# -- Options for manual page output ------------------------------------------
144146

145147
# One entry per manual page. List of tuples
146148
# (source start file, name, description, authors, manual section).
147-
man_pages = [
148-
(master_doc, 'interface', 'interface Documentation',
149-
[author], 1)
150-
]
149+
man_pages = [(master_doc, "interface", "interface Documentation", [author], 1)]
151150

152151

153152
# -- Options for Texinfo output ----------------------------------------------
@@ -156,9 +155,15 @@
156155
# (source start file, target name, title, author,
157156
# dir menu entry, description, category)
158157
texinfo_documents = [
159-
(master_doc, 'interface', 'interface Documentation',
160-
author, 'interface', 'One line description of project.',
161-
'Miscellaneous'),
158+
(
159+
master_doc,
160+
"interface",
161+
"interface Documentation",
162+
author,
163+
"interface",
164+
"One line description of project.",
165+
"Miscellaneous",
166+
),
162167
]
163168

164169

@@ -167,7 +172,7 @@
167172
# -- Options for intersphinx extension ---------------------------------------
168173

169174
# Example configuration for intersphinx: refer to the Python standard library.
170-
intersphinx_mapping = {'https://docs.python.org/': None}
175+
intersphinx_mapping = {"https://docs.python.org/": None}
171176

172177
# -- Options for todo extension ----------------------------------------------
173178

interface/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
from .interface import implements, Interface, InvalidImplementation
33

44
__all__ = [
5-
'default',
6-
'InvalidImplementation',
7-
'Interface',
8-
'implements',
5+
"default",
6+
"InvalidImplementation",
7+
"Interface",
8+
"implements",
99
]

interface/compat.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,22 @@ def viewkeys(d):
3030
def unwrap(func, stop=None):
3131
# NOTE: implementation is taken from CPython/Lib/inspect.py, Python 3.6
3232
if stop is None:
33+
3334
def _is_wrapper(f):
34-
return hasattr(f, '__wrapped__')
35+
return hasattr(f, "__wrapped__")
36+
3537
else:
38+
3639
def _is_wrapper(f):
37-
return hasattr(f, '__wrapped__') and not stop(f)
40+
return hasattr(f, "__wrapped__") and not stop(f)
41+
3842
f = func # remember the original func for error reporting
3943
memo = {id(f)} # Memoise by id to tolerate non-hashable objects
4044
while _is_wrapper(func):
4145
func = func.__wrapped__
4246
id_func = id(func)
4347
if id_func in memo:
44-
raise ValueError('wrapper loop when unwrapping {!r}'.format(f))
48+
raise ValueError("wrapper loop when unwrapping {!r}".format(f))
4549
memo.add(id_func)
4650
return func
4751

@@ -52,8 +56,7 @@ def _is_wrapper(f):
5256

5357
wraps = functools.wraps
5458

55-
exec("def raise_from(e, from_):" # pragma: nocover
56-
" raise e from from_")
59+
exec("def raise_from(e, from_):" " raise e from from_") # pragma: nocover
5760

5861
def viewkeys(d):
5962
return d.keys()
@@ -66,21 +69,21 @@ def with_metaclass(meta, *bases):
6669
# metaclass for one level of class instantiation that replaces itself with
6770
# the actual metaclass.
6871
class metaclass(meta):
69-
7072
def __new__(cls, name, this_bases, d):
7173
return meta(name, bases, d)
72-
return type.__new__(metaclass, 'temporary_class', (), {})
74+
75+
return type.__new__(metaclass, "temporary_class", (), {})
7376

7477

7578
__all__ = [
76-
'PY2',
77-
'PY3',
78-
'Parameter',
79-
'raise_from',
80-
'signature',
81-
'unwrap',
82-
'viewkeys',
83-
'with_metaclass',
84-
'wraps',
85-
'zip_longest',
79+
"PY2",
80+
"PY3",
81+
"Parameter",
82+
"raise_from",
83+
"signature",
84+
"unwrap",
85+
"viewkeys",
86+
"with_metaclass",
87+
"wraps",
88+
"zip_longest",
8689
]

interface/default.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class default(object):
1010
"""Default implementation of a function in terms of interface methods.
1111
"""
12+
1213
def __init__(self, implementation):
1314
self.implementation = implementation
1415

@@ -30,17 +31,19 @@ class UnsafeDefault(UserWarning):
3031
" part of {iface}."
3132
)
3233

33-
def warn_if_defaults_use_non_interface_members(interface_name,
34-
defaults,
35-
members):
34+
def warn_if_defaults_use_non_interface_members(interface_name, defaults, members):
3635
"""Warn if an interface default uses non-interface members of self.
3736
"""
3837
for method_name, attrs in non_member_attributes(defaults, members):
39-
warnings.warn(_DEFAULT_USES_NON_INTERFACE_MEMBER_TEMPLATE.format(
40-
iface=interface_name,
41-
method=method_name,
42-
non_members=bulleted_list(attrs),
43-
), category=UnsafeDefault, stacklevel=3)
38+
warnings.warn(
39+
_DEFAULT_USES_NON_INTERFACE_MEMBER_TEMPLATE.format(
40+
iface=interface_name,
41+
method=method_name,
42+
non_members=bulleted_list(attrs),
43+
),
44+
category=UnsafeDefault,
45+
stacklevel=3,
46+
)
4447

4548
def non_member_attributes(defaults, members):
4649
from .typed_signature import TypedSignature
@@ -90,12 +93,14 @@ def accessed_attributes_of_local(f, local_name):
9093
# It will **NOT** find usages in which ``local_name`` is aliased to
9194
# another name.
9295
for first, second in sliding_window(instrs, 2):
93-
if first.opname == 'LOAD_FAST' and first.argval == local_name:
94-
if second.opname in ('LOAD_ATTR', 'LOAD_METHOD', 'STORE_ATTR'):
96+
if first.opname == "LOAD_FAST" and first.argval == local_name:
97+
if second.opname in ("LOAD_ATTR", "LOAD_METHOD", "STORE_ATTR"):
9598
used.add(second.argval)
9699
return used
97100

101+
98102
else: # pragma: nocover-py3
103+
99104
def warn_if_defaults_use_non_interface_members(*args, **kwargs):
100105
pass
101106

interface/functional.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
def complement(f):
1313
def not_f(*args, **kwargs):
1414
return not f(*args, **kwargs)
15+
1516
return not_f
1617

1718

@@ -28,10 +29,7 @@ def valfilter(f, d):
2829

2930

3031
def dzip(left, right):
31-
return {
32-
k: (left.get(k), right.get(k))
33-
for k in viewkeys(left) & viewkeys(right)
34-
}
32+
return {k: (left.get(k), right.get(k)) for k in viewkeys(left) & viewkeys(right)}
3533

3634

3735
def sliding_window(iterable, n):

0 commit comments

Comments
 (0)