Skip to content

Commit 210a5bb

Browse files
authored
Merge pull request #83 from python-effect/black
use black to format python code, and update travis to run black --check
2 parents 6b71487 + 8f4565f commit 210a5bb

32 files changed

+631
-480
lines changed

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ install:
1010
- pip install .
1111
- pip install -r dev-requirements.txt
1212
- pip install sphinx sphinx_rtd_theme
13+
# black isn't installing on pypy3, so just skip it
14+
- 'if [ "$TRAVIS_PYTHON_VERSION" != "pypy3" ]; then pip install black; fi'
1315
script:
1416
- flake8
15-
- py.test
17+
- 'if [ "$TRAVIS_PYTHON_VERSION" != "pypy3" ]; then black --check .; fi'
18+
- pytest
1619
- make doc
1720

1821
notifications:

docs/source/conf.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# -*- coding: utf-8 -*-
22

33
extensions = [
4-
'sphinx.ext.autodoc',
5-
'sphinx.ext.viewcode',
4+
"sphinx.ext.autodoc",
5+
"sphinx.ext.viewcode",
66
]
77

88
# include __init__ docstrings in class docstrings
9-
autoclass_content = 'both'
9+
autoclass_content = "both"
1010

11-
source_suffix = '.rst'
12-
master_doc = 'index'
13-
project = u'Effect'
14-
copyright = u'2015, Christopher Armstrong'
15-
version = release = '0.12.0+'
11+
source_suffix = ".rst"
12+
master_doc = "index"
13+
project = u"Effect"
14+
copyright = u"2015, Christopher Armstrong"
15+
version = release = "0.12.0+"
1616

17-
html_theme = 'sphinx_rtd_theme'
17+
html_theme = "sphinx_rtd_theme"

effect/__init__.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,42 @@
88
"""
99

1010
from ._base import Effect, perform, NoPerformerFoundError, catch, raise_
11-
from ._sync import (
12-
NotSynchronousError,
13-
sync_perform,
14-
sync_performer)
11+
from ._sync import NotSynchronousError, sync_perform, sync_performer
1512
from ._intents import (
16-
Delay, perform_delay_with_sleep,
17-
ParallelEffects, parallel, parallel_all_errors, FirstError,
18-
Constant, Error, Func,
19-
base_dispatcher)
13+
Delay,
14+
perform_delay_with_sleep,
15+
ParallelEffects,
16+
parallel,
17+
parallel_all_errors,
18+
FirstError,
19+
Constant,
20+
Error,
21+
Func,
22+
base_dispatcher,
23+
)
2024
from ._dispatcher import ComposedDispatcher, TypeDispatcher
2125

2226

2327
__all__ = [
2428
# Order here affects the order that these things show up in the API docs.
25-
"Effect", "sync_perform", "sync_performer",
29+
"Effect",
30+
"sync_perform",
31+
"sync_performer",
2632
"base_dispatcher",
27-
"TypeDispatcher", "ComposedDispatcher",
28-
"Delay", "perform_delay_with_sleep",
29-
"ParallelEffects", "parallel", "parallel_all_errors",
30-
"Constant", "Error", "Func",
31-
"catch", "raise_",
32-
"NoPerformerFoundError", "NotSynchronousError", "perform",
33+
"TypeDispatcher",
34+
"ComposedDispatcher",
35+
"Delay",
36+
"perform_delay_with_sleep",
37+
"ParallelEffects",
38+
"parallel",
39+
"parallel_all_errors",
40+
"Constant",
41+
"Error",
42+
"Func",
43+
"catch",
44+
"raise_",
45+
"NoPerformerFoundError",
46+
"NotSynchronousError",
47+
"perform",
3348
"FirstError",
3449
]

effect/_base.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def on(self, success=None, error=None):
3333
If a callback returns an :obj:`Effect`, the result of that
3434
:obj:`Effect` will be passed to the next callback.
3535
"""
36-
return Effect(self.intent,
37-
callbacks=self.callbacks + [(success, error)])
36+
return Effect(self.intent, callbacks=self.callbacks + [(success, error)])
3837

3938

4039
class _Box(object):
4140
"""
4241
An object into which an effect dispatcher can place a result.
4342
"""
43+
4444
def __init__(self, cont):
4545
"""
4646
:param callable cont: Called with (bool is_error, result)
@@ -119,13 +119,14 @@ def perform(dispatcher, effect):
119119
``box.succeed(result)`` or ``box.fail(exc)``, where ``exc`` is
120120
an exception. Decorators like :func:`sync_performer` simply abstract this away.
121121
"""
122+
122123
def _run_callbacks(bouncer, chain, result):
123124
is_error, value = result
124125

125126
if type(value) is Effect:
126127
bouncer.bounce(
127-
_perform,
128-
Effect(value.intent, callbacks=value.callbacks + chain))
128+
_perform, Effect(value.intent, callbacks=value.callbacks + chain)
129+
)
129130
return
130131

131132
if not chain:
@@ -146,8 +147,8 @@ def _perform(bouncer, effect):
146147
performer(
147148
dispatcher,
148149
effect.intent,
149-
_Box(partial(bouncer.bounce,
150-
_run_callbacks, effect.callbacks)))
150+
_Box(partial(bouncer.bounce, _run_callbacks, effect.callbacks)),
151+
)
151152
except Exception as e:
152153
_run_callbacks(bouncer, effect.callbacks, (True, e))
153154

@@ -164,10 +165,12 @@ def catch(exc_type, callable):
164165
If any exception other than a ``SpecificException`` is thrown, it will be
165166
ignored by this handler and propogate further down the chain of callbacks.
166167
"""
168+
167169
def catcher(error):
168170
if isinstance(error, exc_type):
169171
return callable(error)
170172
raise error
173+
171174
return catcher
172175

173176

effect/_continuation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def bounce(self, func, *args, **kwargs):
1919
if self.work is not None:
2020
raise RuntimeError(
2121
"Already specified work %r, refusing to set to (%r %r %r)"
22-
% (self.work, func, args, kwargs))
22+
% (self.work, func, args, kwargs)
23+
)
2324
self.work = (func, args, kwargs)
2425
if self._asynchronous:
2526
trampoline(func, *args, **kwargs)

effect/_dispatcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TypeDispatcher(object):
1212
1313
:param mapping: mapping of intent type to performer
1414
"""
15+
1516
mapping = attr.ib()
1617

1718
def __call__(self, intent):

effect/_intents.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ def parallel_all_errors(effects):
7878
False, then ``result`` will just be the result as provided by the child
7979
effect.
8080
"""
81-
effects = [effect.on(success=lambda r: (False, r),
82-
error=lambda e: (True, e))
83-
for effect in effects]
81+
effects = [
82+
effect.on(success=lambda r: (False, r), error=lambda e: (True, e))
83+
for effect in effects
84+
]
8485
return Effect(ParallelEffects(list(effects)))
8586

8687

@@ -90,12 +91,16 @@ class FirstError(Exception):
9091
One of the effects in a :obj:`ParallelEffects` resulted in an error. This
9192
represents the first such error that occurred.
9293
"""
94+
9395
exception = attr.ib()
9496
index = attr.ib()
9597

9698
def __str__(self):
97-
return '(index=%s) %s: %s' % (
98-
self.index, type(self.exception).__name__, self.exception)
99+
return "(index=%s) %s: %s" % (
100+
self.index,
101+
type(self.exception).__name__,
102+
self.exception,
103+
)
99104

100105

101106
@attr.s
@@ -108,6 +113,7 @@ class Delay(object):
108113
109114
:param float delay: The number of seconds to delay.
110115
"""
116+
111117
delay = attr.ib()
112118

113119

@@ -124,6 +130,7 @@ class Constant(object):
124130
125131
:param result: The object which the Effect will result in.
126132
"""
133+
127134
result = attr.ib()
128135

129136

@@ -140,6 +147,7 @@ class Error(object):
140147
141148
:param BaseException exception: Exception instance to raise.
142149
"""
150+
143151
exception = attr.ib()
144152

145153

@@ -173,6 +181,7 @@ class Func(object):
173181
:param args: Positional arguments to pass to the function.
174182
:param kwargs: Keyword arguments to pass to the function.
175183
"""
184+
176185
func = attr.ib()
177186
args = attr.ib()
178187
kwargs = attr.ib()
@@ -189,8 +198,6 @@ def perform_func(dispatcher, intent):
189198
return intent.func(*intent.args, **intent.kwargs)
190199

191200

192-
base_dispatcher = TypeDispatcher({
193-
Constant: perform_constant,
194-
Error: perform_error,
195-
Func: perform_func,
196-
})
201+
base_dispatcher = TypeDispatcher(
202+
{Constant: perform_constant, Error: perform_error, Func: perform_func}
203+
)

effect/_sync.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ def sync_perform(dispatcher, effect):
3030
elif errors:
3131
raise errors[0]
3232
else:
33-
raise NotSynchronousError("Performing %r was not synchronous!"
34-
% (effect,))
33+
raise NotSynchronousError("Performing %r was not synchronous!" % (effect,))
3534

3635

3736
def sync_performer(f):
@@ -61,6 +60,7 @@ def sync_performer(f):
6160
def perform_foo(dispatcher, foo):
6261
return do_side_effect(foo)
6362
"""
63+
6464
@wraps(f)
6565
def sync_wrapper(*args, **kwargs):
6666
box = args[-1]
@@ -69,4 +69,5 @@ def sync_wrapper(*args, **kwargs):
6969
box.succeed(f(*pass_args, **kwargs))
7070
except Exception as e:
7171
box.fail(e)
72+
7273
return sync_wrapper

effect/_test_utils.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class ReraisedTracebackMismatch(object):
1313
got_tb = attr.ib()
1414

1515
def describe(self):
16-
return ("The reference traceback:\n"
17-
+ ''.join(self.expected_tb)
18-
+ "\nshould match the tail end of the received traceback:\n"
19-
+ ''.join(self.got_tb)
20-
+ "\nbut it doesn't.")
16+
return (
17+
"The reference traceback:\n"
18+
+ "".join(self.expected_tb)
19+
+ "\nshould match the tail end of the received traceback:\n"
20+
+ "".join(self.got_tb)
21+
+ "\nbut it doesn't."
22+
)
23+
2124

2225
@attr.s
2326
class MatchesException(object):
@@ -26,10 +29,11 @@ class MatchesException(object):
2629
def match(self, other):
2730
expected_type = type(self.expected)
2831
if type(other) is not expected_type:
29-
return Mismatch('{} is not a {}'.format(other, expected_type))
32+
return Mismatch("{} is not a {}".format(other, expected_type))
3033
if other.args != self.expected.args:
31-
return Mismatch('{} has different arguments: {}.'.format(
32-
other.args, self.expected.args))
34+
return Mismatch(
35+
"{} has different arguments: {}.".format(other.args, self.expected.args)
36+
)
3337

3438

3539
@attr.s
@@ -44,12 +48,13 @@ def match(self, actual):
4448
typecheck = Equals(type(self.expected)).match(type(actual))
4549
if typecheck is not None:
4650
return typecheck
47-
expected = list(traceback.TracebackException.from_exception(self.expected).format())
51+
expected = list(
52+
traceback.TracebackException.from_exception(self.expected).format()
53+
)
4854
new = list(traceback.TracebackException.from_exception(actual).format())
49-
tail_equals = lambda a, b: a == b[-len(a):]
55+
tail_equals = lambda a, b: a == b[-len(a) :]
5056
if not tail_equals(expected[1:], new[1:]):
51-
return ReraisedTracebackMismatch(expected_tb=expected,
52-
got_tb=new)
57+
return ReraisedTracebackMismatch(expected_tb=expected, got_tb=new)
5358

5459

5560
def raise_(e):

effect/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def wraps(original):
1010
This is like :func:`functools.wraps`, except you can wrap non-functions
1111
without blowing up.
1212
"""
13+
1314
def wraps_decorator(wrapper):
1415
try:
1516
wrapper.__name__ = original.__name__
@@ -19,4 +20,5 @@ def wraps_decorator(wrapper):
1920
except:
2021
pass
2122
return wrapper
23+
2224
return wraps_decorator

0 commit comments

Comments
 (0)