Skip to content

Commit 93793db

Browse files
committed
Format the source code using Black
1 parent 900c2b3 commit 93793db

File tree

5 files changed

+27
-40
lines changed

5 files changed

+27
-40
lines changed

example.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(self, app):
7979
self.app = app
8080

8181
"""Configure the application."""
82+
8283
def configure(self, binder):
8384
# We configure the DB here, explicitly, as Flask-SQLAlchemy requires
8485
# the DB to be configured before request handlers are called.
@@ -88,20 +89,14 @@ def configure(self, binder):
8889
def configure_db(self, app):
8990
db = SQLAlchemy(app)
9091
Base.metadata.create_all(db.engine)
91-
db.session.add_all([
92-
KeyValue('hello', 'world'),
93-
KeyValue('goodbye', 'cruel world'),
94-
])
92+
db.session.add_all([KeyValue('hello', 'world'), KeyValue('goodbye', 'cruel world')])
9593
db.session.commit()
9694
return db
9795

9896

9997
def main():
10098
app = Flask(__name__)
101-
app.config.update(
102-
DB_CONNECTION_STRING=':memory:',
103-
SQLALCHEMY_DATABASE_URI='sqlite://',
104-
)
99+
app.config.update(DB_CONNECTION_STRING=':memory:', SQLALCHEMY_DATABASE_URI='sqlite://')
105100
app.debug = True
106101

107102
injector = Injector([AppModule(app)])

flask_injector.py

+14-18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Any, Callable, cast, Dict, get_type_hints, Iterable, List, TypeVar, Union
1414

1515
import flask
16+
1617
try:
1718
from flask_restful import Api as FlaskRestfulApi
1819
from flask_restful.utils import unpack as flask_response_unpack
@@ -33,7 +34,7 @@
3334

3435
__author__ = 'Alec Thomas <[email protected]>'
3536
__version__ = '0.11.0'
36-
__all__ = ['request', 'RequestScope', 'Config', 'Request', 'FlaskInjector', ]
37+
__all__ = ['request', 'RequestScope', 'Config', 'Request', 'FlaskInjector']
3738

3839
T = TypeVar('T', LocalProxy, Callable)
3940

@@ -42,6 +43,7 @@ def instance_method_wrapper(im: T) -> T:
4243
@functools.wraps(im)
4344
def wrapper(*args: Any, **kwargs: Any) -> Any:
4445
return im(*args, **kwargs)
46+
4547
return wrapper # type: ignore
4648

4749

@@ -85,6 +87,7 @@ def wrap_function(fun: Callable, injector: Injector) -> Callable:
8587
@functools.wraps(fun)
8688
def wrapper(*args: Any, **kwargs: Any) -> Any:
8789
return injector.call_with_injection(callable=fun, args=args, kwargs=kwargs)
90+
8891
return wrapper
8992

9093

@@ -110,11 +113,7 @@ def wrap_class_based_view(fun: Callable, injector: Injector) -> Callable:
110113
class_args = fun_closure.get('class_args')
111114
assert not class_args, 'Class args are not supported, use kwargs instead'
112115

113-
if (
114-
flask_restful_api
115-
and flask_restplus
116-
and isinstance(flask_restful_api, flask_restplus.Api)
117-
):
116+
if flask_restful_api and flask_restplus and isinstance(flask_restful_api, flask_restplus.Api):
118117
# This is flask_restplus' add_resource implementation:
119118
#
120119
# def add_resource(self, resource, *urls, **kwargs):
@@ -173,9 +172,7 @@ def view(*args: Any, **kwargs: Any) -> Any:
173172

174173

175174
def wrap_flask_restful_resource(
176-
fun: Callable,
177-
flask_restful_api: FlaskRestfulApi,
178-
injector: Injector,
175+
fun: Callable, flask_restful_api: FlaskRestfulApi, injector: Injector
179176
) -> Callable:
180177
"""
181178
This is needed because of how flask_restful views are registered originally.
@@ -309,13 +306,13 @@ def __init__(
309306
injector.binder.install(module)
310307

311308
for container in (
312-
app.view_functions,
313-
app.before_request_funcs,
314-
app.after_request_funcs,
315-
app.teardown_request_funcs,
316-
app.template_context_processors,
317-
app.jinja_env.globals,
318-
app.error_handler_spec,
309+
app.view_functions,
310+
app.before_request_funcs,
311+
app.after_request_funcs,
312+
app.teardown_request_funcs,
313+
app.template_context_processors,
314+
app.jinja_env.globals,
315+
app.error_handler_spec,
319316
):
320317
process_dict(container, injector)
321318

@@ -332,8 +329,7 @@ def reset_request_scope_before(*args: Any, **kwargs: Any) -> None:
332329
def reset_request_scope_after(*args: Any, **kwargs: Any) -> None:
333330
injector_not_null.get(request_scope_class).cleanup()
334331

335-
app.before_request_funcs.setdefault(
336-
None, []).insert(0, reset_request_scope_before)
332+
app.before_request_funcs.setdefault(None, []).insert(0, reset_request_scope_before)
337333
app.teardown_request(reset_request_scope_after)
338334

339335
self.injector = injector_not_null

flask_injector_tests.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def get_request():
160160
# Force run garbage collect to make sure GreenThread object is collected if
161161
# there is no memory leak
162162
gc.collect()
163-
greenthread_count = len([
164-
obj for obj in gc.get_objects()
165-
if type(obj) is greenthread.GreenThread])
163+
greenthread_count = len([obj for obj in gc.get_objects() if type(obj) is greenthread.GreenThread])
166164

167165
eq_(greenthread_count, 0)
168166

@@ -235,12 +233,10 @@ def configure(binder):
235233

236234
with app.test_client() as c:
237235
response = c.get('/this-page-does-not-exist')
238-
eq_((response.status_code, response.get_data(as_text=True)),
239-
(404, 'injected content'))
236+
eq_((response.status_code, response.get_data(as_text=True)), (404, 'injected content'))
240237

241238
response = c.get('/custom-exception')
242-
eq_((response.status_code, response.get_data(as_text=True)),
243-
(500, 'injected content'))
239+
eq_((response.status_code, response.get_data(as_text=True)), (500, 'injected content'))
244240

245241

246242
def test_view_functions_arent_modified_globally():
@@ -268,9 +264,7 @@ class MyView(View):
268264

269265

270266
def test_view_args_and_class_args_are_passed_to_class_based_views():
271-
272267
class MyView(View):
273-
274268
def __init__(self, class_arg):
275269
self.class_arg = class_arg
276270

@@ -289,7 +283,6 @@ def dispatch_request(self, dispatch_arg):
289283

290284

291285
def test_flask_restful_integration_works():
292-
293286
class HelloWorld(flask_restful.Resource):
294287
@inject
295288
def __init__(self, *args, int: int, **kwargs):
@@ -369,7 +362,7 @@ class HelloWorldService:
369362
def get_value(self):
370363
return "test message 1"
371364

372-
class HelloWorld():
365+
class HelloWorld:
373366
def from_injected_service(self, service: HelloWorldService):
374367
return service.get_value()
375368

@@ -392,6 +385,7 @@ def static_value(self):
392385

393386

394387
if injector_version >= '0.12':
388+
395389
def test_forward_references_work():
396390
app = Flask(__name__)
397391

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool.black]
2+
line-length = 110
3+
target_version = ['py36', 'py37']
4+
skip_string_normalization = true

setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
# very convoluted way of reading version from the module without importing it
77
version = (
8-
[l for l in open('flask_injector.py') if '__version__ = ' in l][0]
9-
.split('=')[-1]
10-
.strip().strip('\'')
8+
[l for l in open('flask_injector.py') if '__version__ = ' in l][0].split('=')[-1].strip().strip('\'')
119
)
1210

1311
if __name__ == '__main__':

0 commit comments

Comments
 (0)