Skip to content

Commit c2473c0

Browse files
committed
lint fixes 1
1 parent 74a75f7 commit c2473c0

27 files changed

Lines changed: 189 additions & 186 deletions

File tree

agave/chalice/rest_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mimetypes
2-
from typing import Any, Optional, Type, cast
2+
from typing import Any, Callable, NoReturn, Optional, Type, cast
33
from urllib.parse import urlencode
44

55
try:
@@ -18,31 +18,31 @@
1818

1919

2020
class RestApiBlueprint(Blueprint):
21-
def get(self, path: str, **kwargs):
21+
def get(self, path: str, **kwargs) -> Callable:
2222
return self.route(path, methods=['GET'], **kwargs)
2323

24-
def post(self, path: str, **kwargs):
24+
def post(self, path: str, **kwargs) -> Callable:
2525
return self.route(path, methods=['POST'], **kwargs)
2626

27-
def patch(self, path: str, **kwargs):
27+
def patch(self, path: str, **kwargs) -> Callable:
2828
return self.route(path, methods=['PATCH'], **kwargs)
2929

30-
def delete(self, path: str, **kwargs):
30+
def delete(self, path: str, **kwargs) -> Callable:
3131
return self.route(path, methods=['DELETE'], **kwargs)
3232

3333
@property
34-
def current_user_id(self):
34+
def current_user_id(self) -> str:
3535
return self.current_request.context['user_id']
3636

3737
@property
38-
def current_platform_id(self):
38+
def current_platform_id(self) -> str:
3939
return self.current_request.context['platform_id']
4040

4141
@property
42-
def current_api_key_id(self):
42+
def current_api_key_id(self) -> str:
4343
return self.current_request.context['api_key_id']
4444

45-
def user_id_filter_required(self):
45+
def user_id_filter_required(self) -> bool:
4646
"""
4747
This method is required to be implemented with your own business logic.
4848
You are responsible of determining when `user_id` filter is required.
@@ -51,7 +51,7 @@ def user_id_filter_required(self):
5151
'this method should be override'
5252
) # pragma: no cover
5353

54-
def platform_id_filter_required(self):
54+
def platform_id_filter_required(self) -> bool:
5555
"""
5656
This method is required to be implemented with your own business logic.
5757
You are responsible of determining when `user_id` filter is required.
@@ -81,7 +81,7 @@ def retrieve_object(self, resource_class: Any, resource_id: str) -> Any:
8181
raise NotFoundError('Not valid id')
8282
return data
8383

84-
def validate(self, validation_type: Type[BaseModel]):
84+
def validate(self, validation_type: Type[BaseModel]) -> Callable:
8585
"""This decorator validate the request body using a
8686
custom pydantyc model. If validation fails return a
8787
BadRequest response with details
@@ -103,7 +103,7 @@ def wrapper(*args, **kwargs):
103103

104104
return decorator
105105

106-
def resource(self, path: str):
106+
def resource(self, path: str) -> Callable:
107107
"""Decorator to transform a class in Chalice REST endpoints
108108
109109
@app.resource('/my_resource')
@@ -164,7 +164,7 @@ def delete(id: str):
164164

165165
@copy_attributes(cls)
166166
def update(id: str):
167-
params = self.current_request.json_body or dict()
167+
params = self.current_request.json_body or {}
168168
try:
169169
data = cls.update_validator(**params)
170170
except ValidationError as e:
@@ -238,7 +238,7 @@ def query():
238238
next_page = <url_for_next_items>
239239
}
240240
"""
241-
params = self.current_request.query_params or dict()
241+
params = self.current_request.query_params or {}
242242
try:
243243
query_params = cls.query_validator(**params)
244244
except ValidationError as e:
@@ -272,7 +272,7 @@ def query():
272272

273273
def _count(filters: Q):
274274
count = cls.model.objects.filter(filters).count()
275-
return dict(count=count)
275+
return {'count': count}
276276

277277
def _all(query: QueryParams, filters: Q):
278278
if query.limit:
@@ -302,7 +302,7 @@ def _all(query: QueryParams, filters: Q):
302302
if self.platform_id_filter_required():
303303
params.pop('platform_id')
304304
next_page_uri = f'{path}?{urlencode(params)}'
305-
return dict(items=item_dicts, next_page_uri=next_page_uri)
305+
return {'items': item_dicts, 'next_page_uri': next_page_uri}
306306

307307
return cls
308308

agave/core/blueprints/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, Callable, Type
22

33

4-
def copy_attributes(resource: Type[Any]):
4+
def copy_attributes(resource: Type[Any]) -> Callable:
55
"""
66
Copy every attached property from resource methods definition to the
77
real function handler.

agave/fastapi/middlewares/error_handlers.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ async def dispatch(
2121
except CuencaError as exc:
2222
return JSONResponse(
2323
status_code=exc.status_code,
24-
content=dict(
25-
code=exc.code,
26-
error=str(exc),
27-
),
24+
content={
25+
'code': exc.code,
26+
'error': str(exc),
27+
},
2828
)
2929
except AgaveError as exc:
3030
return JSONResponse(
31-
status_code=exc.status_code, content=dict(error=exc.error)
31+
status_code=exc.status_code, content={'error': exc.error}
3232
)
3333

3434

agave/fastapi/rest_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mimetypes
2-
from typing import Any, Optional
2+
from typing import Any, Callable, Optional
33
from urllib.parse import urlencode
44

55
from cuenca_validations.types import QueryParams
@@ -83,7 +83,7 @@ async def retrieve_object(
8383
raise NotFoundError('Not valid id')
8484
return data
8585

86-
def resource(self, path: str):
86+
def resource(self, path: str) -> Callable:
8787
"""Decorator to transform a class in FastApi REST endpoints
8888
8989
@app.resource('/my_resource')
@@ -111,7 +111,7 @@ def wrapper_resource_class(cls):
111111
:param cls: Resoucre class
112112
:return:
113113
"""
114-
response_model = Any
114+
response_model: type[BaseModel] = None
115115
response_sample = {}
116116
include_in_schema = getattr(cls, 'include_in_schema', True)
117117
if hasattr(cls, 'response_model'):
@@ -399,7 +399,7 @@ async def query(
399399

400400
async def _count(filters: Q):
401401
count = await cls.model.objects.filter(filters).async_count()
402-
return dict(count=count)
402+
return {'count': count}
403403

404404
async def _all(query: QueryParams, filters: Q, resource_path: str):
405405
if query.limit:
@@ -431,7 +431,7 @@ async def _all(query: QueryParams, filters: Q, resource_path: str):
431431
if self.platform_id_filter_required():
432432
params.pop('platform_id')
433433
next_page_uri = f'{resource_path}?{urlencode(params)}'
434-
return dict(items=item_dicts, next_page_uri=next_page_uri)
434+
return {'items': item_dicts, 'next_page_uri': next_page_uri}
435435

436436
return cls
437437

agave/tasks/sqs_tasks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from functools import wraps
77
from itertools import count
88
from json import JSONDecodeError
9-
from typing import Callable
9+
from typing import Any, Callable, List
1010

1111
from aiobotocore.httpsession import HTTPClientError
1212
from aiobotocore.session import get_session
@@ -121,7 +121,7 @@ async def message_consumer(
121121
yield message
122122

123123

124-
async def get_running_fast_agave_tasks():
124+
async def get_running_fast_agave_tasks() -> List[Any]:
125125
return [
126126
t
127127
for t in asyncio.all_tasks()
@@ -136,7 +136,7 @@ def task(
136136
visibility_timeout: int = 3600,
137137
max_retries: int = 1,
138138
max_concurrent_tasks: int = 5,
139-
):
139+
) -> Callable:
140140
def task_builder(task_func: Callable):
141141
@wraps(task_func)
142142
async def start_task(*args, **kwargs) -> None:

agave/tools/asyncio/sqs_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ async def __aexit__(
3737
) -> None:
3838
await self.close()
3939

40-
async def start(self):
40+
async def start(self) -> None:
4141
session = get_session()
4242
context = session.create_client('sqs', self.region_name)
4343
self._background_tasks = set()
4444
self._sqs = await context.__aenter__()
4545

46-
async def close(self):
46+
async def close(self) -> None:
4747
await self._sqs.__aexit__(None, None, None)
4848

4949
async def send_message(

agave/tools/celery.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ def build_celery_message(
1515
task_id = str(uuid4())
1616
# la definición de esta plantila se encuentra en:
1717
# docs.celeryproject.org/en/stable/internals/protocol.html#definition
18-
message = dict(
19-
properties=dict(
20-
correlation_id=task_id,
21-
content_type='application/json',
22-
content_encoding='utf-8',
23-
body_encoding='base64',
24-
delivery_info=dict(exchange='', routing_key='celery'),
25-
),
26-
headers=dict(
27-
lang='py',
28-
task=task_name,
29-
id=task_id,
30-
root_id=task_id,
31-
parent_id=None,
32-
group=None,
33-
),
34-
body=_b64_encode(
18+
message = {
19+
'properties': {
20+
'correlation_id': task_id,
21+
'content_type': 'application/json',
22+
'content_encoding': 'utf-8',
23+
'body_encoding': 'base64',
24+
'delivery_info': {'exchange': '', 'routing_key': 'celery'},
25+
},
26+
'headers': {
27+
'lang': 'py',
28+
'task': task_name,
29+
'id': task_id,
30+
'root_id': task_id,
31+
'parent_id': None,
32+
'group': None,
33+
},
34+
'body': _b64_encode(
3535
json.dumps(
3636
(
3737
args_,
3838
kwargs_,
39-
dict(
40-
callbacks=None, errbacks=None, chain=None, chord=None
41-
),
39+
{
40+
'callbacks': None, 'errbacks': None, 'chain': None, 'chord': None
41+
},
4242
)
4343
)
4444
),
45-
)
45+
}
4646
message['content-encoding'] = 'utf-8'
4747
message['content-type'] = 'application/json'
4848

examples/chalice/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020

2121

2222
@app.route('/')
23-
def health_check():
24-
return dict(greeting="I'm testing app!!!")
23+
def health_check() -> dict:
24+
return {'greeting': "I'm testing app!!!"}

examples/chalice/blueprints/authed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class AuthedBlueprint(Blueprint):
1616
1717
"""
1818

19-
def route(self, path: str, **kwargs):
19+
def route(self, path: str, **kwargs) -> Callable:
2020
"""
2121
Builds route decorator with custom authentication.
2222
It is only a function wrapper for `Blueprint._register_handler` methods
@@ -48,12 +48,12 @@ def authed_handler(*args, **kwargs):
4848
user_handler.__name__,
4949
authed_handler,
5050
authed_handler,
51-
dict(path=path, kwargs=kwargs),
51+
{'path': path, 'kwargs': kwargs},
5252
)
5353

5454
return decorator
5555

56-
def user_id_filter_required(self):
56+
def user_id_filter_required(self) -> bool:
5757
"""
5858
It overrides `RestApiBlueprint.user_id_filter_required()` method.
5959
@@ -74,7 +74,7 @@ def user_id_filter_required(self):
7474
"""
7575
return False
7676

77-
def platform_id_filter_required(self):
77+
def platform_id_filter_required(self) -> bool:
7878
"""
7979
It overrides `RestApiBlueprint.platform_id_filter_required()` method.
8080
:return:

examples/chalice/resources/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
@app.get('/healthy_auth')
77
def health_auth_check() -> dict:
8-
return dict(greeting="I'm authenticated and healthy !!!")
8+
return {'greeting': "I'm authenticated and healthy !!!"}

0 commit comments

Comments
 (0)