Skip to content

Commit

Permalink
Merge pull request #45 from ssanderson/pin-black
Browse files Browse the repository at this point in the history
STY: Update and pin black version.
  • Loading branch information
ssanderson authored Apr 21, 2021
2 parents 4f9a396 + e4b0119 commit d25b3cc
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ repos:
hooks:
- id: isort

- repo: https://github.com/ambv/black
rev: stable
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3.6
6 changes: 2 additions & 4 deletions interface/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@


class default(object):
"""Default implementation of a function in terms of interface methods.
"""
"""Default implementation of a function in terms of interface methods."""

def __init__(self, implementation):
self.implementation = implementation
Expand All @@ -32,8 +31,7 @@ class UnsafeDefault(UserWarning):
)

def warn_if_defaults_use_non_interface_members(interface_name, defaults, members):
"""Warn if an interface default uses non-interface members of self.
"""
"""Warn if an interface default uses non-interface members of self."""
for method_name, attrs in non_member_attributes(defaults, members):
warnings.warn(
_DEFAULT_USES_NON_INTERFACE_MEMBER_TEMPLATE.format(
Expand Down
28 changes: 21 additions & 7 deletions interface/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def _conflicting_defaults(typename, conflicts):
The following interfaces provided default implementations for {attr!r}:
{interfaces}"""
).format(
attr=attrname, interfaces=bulleted_list(sorted(map(getname, interfaces))),
attr=attrname,
interfaces=bulleted_list(sorted(map(getname, interfaces))),
)
return InvalidImplementation(message)

Expand Down Expand Up @@ -116,7 +117,9 @@ def __new__(mcls, name, bases, clsdict):
errmsg = (
"Couldn't parse signature for field "
"{iface_name}.{fieldname} of type {attrtype}.".format(
iface_name=name, fieldname=field, attrtype=getname(type(v)),
iface_name=name,
fieldname=field,
attrtype=getname(type(v)),
)
)
raise_from(TypeError(errmsg), e)
Expand All @@ -131,7 +134,10 @@ def __new__(mcls, name, bases, clsdict):
"\nInterface field {new}.{field} conflicts with inherited field of "
"the same name.\n"
" - {field}{new_sig} != {field}{old_sig}".format(
new=name, field=field, new_sig=signature, old_sig=conflicted,
new=name,
field=field,
new_sig=signature,
old_sig=conflicted,
)
)
else:
Expand Down Expand Up @@ -228,7 +234,8 @@ def _invalid_implementation(self, t, missing, mistyped, mismatched):
assert missing or mistyped or mismatched, "Implementation wasn't invalid."

message = "\nclass {C} failed to implement interface {I}:".format(
C=getname(t), I=getname(self),
C=getname(t),
I=getname(self),
)
if missing:
message += dedent(
Expand Down Expand Up @@ -293,7 +300,9 @@ def _format_mismatched_methods(self, mismatched):
sorted(
[
" - {name}{actual} != {name}{expected}".format(
name=name, actual=bad_sig, expected=self._signatures[name],
name=name,
actual=bad_sig,
expected=self._signatures[name],
)
for name, bad_sig in mismatched.items()
]
Expand Down Expand Up @@ -470,7 +479,9 @@ def format_iface_method_docs(I):
return "\n".join(
[
"{iface_name}.{method_name}{sig}".format(
iface_name=iface_name, method_name=method_name, sig=sig,
iface_name=iface_name,
method_name=method_name,
sig=sig,
)
for method_name, sig in sorted(list(I._signatures.items()), key=first)
]
Expand Down Expand Up @@ -564,7 +575,10 @@ def method2(self, y):
)

result = ImplementsMeta(
name, (object,), {"__doc__": doc}, interfaces=interfaces,
name,
(object,),
{"__doc__": doc},
interfaces=interfaces,
)

# NOTE: It's important for correct weak-memoization that this is set is
Expand Down
4 changes: 4 additions & 0 deletions interface/tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ def method_b(self):

# expected to fail since it's missing method_b
with pytest.raises(InvalidImplementation) as exc:

class JustA(implements(AandB)): # pragma: nocover
def method_a(self):
pass
Expand All @@ -919,6 +920,7 @@ class JustA failed to implement interface AandB:

# expected to fail since it's missing method_a
with pytest.raises(InvalidImplementation) as exc:

class JustB(implements(AandB)): # pragma: nocover
def method_b(self):
pass
Expand Down Expand Up @@ -958,6 +960,7 @@ def method_b(self):

# expected to fail since method_a has different signature in interface A
with pytest.raises(TypeError) as exc:

class C1(A): # pragma: nocover
def method_a(self, x):
pass
Expand All @@ -972,6 +975,7 @@ def method_a(self, x):

# expected to fail since method_b has different signature in interface B
with pytest.raises(TypeError) as exc:

class C2(B): # pragma: nocover
def method_b(self, y, z=None):
pass
Expand Down
3 changes: 2 additions & 1 deletion interface/typed_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def __str__(self):

def __repr__(self):
return "<TypedSignature type={}, signature={}>".format(
self._type.__name__, self._signature,
self._type.__name__,
self._signature,
)


Expand Down

0 comments on commit d25b3cc

Please sign in to comment.