Skip to content

Commit d4290ec

Browse files
Flake8 everything (#610)
1 parent 6240718 commit d4290ec

22 files changed

+47
-46
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ ignore = E226,E501,E722,W503
1111
per-file-ignores =
1212
# S101: Pytest uses assert
1313
tests/*:S101
14+
# I900: Requirements for examples shouldn't be included
15+
examples/*:I900
1416

1517
# flake8-import-order
16-
application-import-names = aiohttp_session
1718
import-order-style = pycharm
1819

1920
# flake8-quotes

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Some simple testing tasks (sorry, UNIX only).
22

33
flake:
4-
flake8 aiohttp_session tests
4+
flake8
55

66

77
test: flake

demo/flash_messages_example.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import base64
22
from typing import Awaitable, Callable, List, NoReturn, cast
33

4-
from cryptography import fernet
54
from aiohttp import web
6-
from aiohttp_session import setup, get_session
5+
from aiohttp_session import get_session, setup
76
from aiohttp_session.cookie_storage import EncryptedCookieStorage
7+
from cryptography import fernet
88

99
_Handler = Callable[[web.Request], Awaitable[web.StreamResponse]]
1010

@@ -22,8 +22,8 @@ async def process(request: web.Request) -> web.StreamResponse:
2222
session = await get_session(request)
2323
request['flash_incoming'] = session.pop('flash', [])
2424
response = await handler(request)
25-
session['flash'] = (request.get('flash_incoming', []) +
26-
request.get('flash_outgoing', []))
25+
session['flash'] = (request.get('flash_incoming', [])
26+
+ request.get('flash_outgoing', []))
2727
return response
2828
return process
2929

@@ -55,4 +55,3 @@ def make_app() -> web.Application:
5555

5656

5757
web.run_app(make_app())
58-

demo/login_required_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
from http import HTTPStatus
33
from typing import Any, Awaitable, Callable
44

5-
from cryptography import fernet
65
from aiohttp import web
7-
from aiohttp_session import setup, get_session, new_session
6+
from aiohttp_session import get_session, new_session, setup
87
from aiohttp_session.cookie_storage import EncryptedCookieStorage
8+
from cryptography import fernet
99

1010

1111
DATABASE = [

demo/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import time
21
import base64
3-
from cryptography import fernet
2+
import time
3+
44
from aiohttp import web
5-
from aiohttp_session import setup, get_session
5+
from aiohttp_session import get_session, setup
66
from aiohttp_session.cookie_storage import EncryptedCookieStorage
7+
from cryptography import fernet
78

89

910
async def handler(request: web.Request) -> web.Response:

demo/memcached_storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import time
2-
from aiohttp import web
31
import asyncio
4-
import aiomcache
5-
from aiohttp_session import setup, get_session
2+
import time
63

4+
import aiomcache
5+
from aiohttp import web
6+
from aiohttp_session import get_session, setup
77
from aiohttp_session.memcached_storage import MemcachedStorage
88

99

demo/redis_storage.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import asyncio
2-
import aioredis
31
import time
42
from typing import AsyncIterator
53

4+
import aioredis
65
from aiohttp import web
7-
from aiohttp_session import setup, get_session
6+
from aiohttp_session import get_session, setup
87
from aiohttp_session.redis_storage import RedisStorage
98

109

@@ -16,7 +15,7 @@ async def handler(request: web.Request) -> web.Response:
1615
return web.Response(text=text)
1716

1817

19-
async def redis_pool(app: web.Application) -> AsyncIterator[aioredis.commands.Redis]: # type: ignore[no-any-unimported]
18+
async def redis_pool(app: web.Application) -> AsyncIterator[aioredis.commands.Redis]: # type: ignore[no-any-unimported] # noqa: B950
2019
redis_address = ('127.0.0.1', '6379')
2120
async with await aioredis.create_redis_pool(redis_address, timeout=1) as redis:
2221
storage = RedisStorage(redis)

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# All configuration values have a default; values that are commented out
1414
# serve to show the default.
1515

16-
import sys
17-
import os
1816
import codecs
17+
import os
1918
import re
19+
import sys
2020

2121
_docs_path = os.path.dirname(__file__)
2222
_version_path = os.path.abspath(os.path.join(_docs_path,

examples/postgres_storage.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import uuid
3-
from typing import Any, Callable, Dict, Optional
3+
from typing import Any, Callable, Optional
44

55
import psycopg2.extras
66
from aiohttp import web
@@ -11,7 +11,7 @@
1111
class PgStorage(AbstractStorage):
1212
"""PG storage"""
1313

14-
def __init__(self, pg_pool: Pool, *, cookie_name: str = "AIOHTTP_SESSION", # type: ignore[no-any-unimported]
14+
def __init__(self, pg_pool: Pool, *, cookie_name: str = "AIOHTTP_SESSION", # type: ignore[no-any-unimported] # noqa: B950
1515
domain: Optional[str] = None, max_age: Optional[int] = None,
1616
path: str = '/', secure: Optional[bool] = None, httponly: bool = True,
1717
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
@@ -34,7 +34,8 @@ async def load_session(self, request: web.Request) -> Session:
3434
key = uuid.UUID(cookie)
3535
async with conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as cur:
3636

37-
await cur.execute("SELECT session, extract(epoch from created) FROM web.sessions WHERE uuid = %s", (key,))
37+
await cur.execute("SELECT session, extract(epoch from created) " # noqa: S608
38+
+ "FROM web.sessions WHERE uuid = %s", (key,))
3839
data = await cur.fetchone()
3940

4041
if not data:
@@ -63,9 +64,10 @@ async def save_session(self, request: web.Request, response: web.StreamResponse,
6364
expire = data["created"] + (session.max_age or 0)
6465
async with self._pg.acquire() as conn:
6566
async with conn.cursor() as cur:
66-
await cur.execute("INSERT INTO web.sessions (uuid,session,created,expire)"
67-
" VALUES (%s, %s, to_timestamp(%s),to_timestamp(%s))"
68-
" ON CONFLICT (uuid)"
69-
" DO UPDATE"
70-
" SET (session,expire)=(EXCLUDED.session, EXCLUDED.expire)",
67+
await cur.execute(
68+
"INSERT INTO web.sessions (uuid,session,created,expire)" # noqa: S608
69+
+ " VALUES (%s, %s, to_timestamp(%s),to_timestamp(%s))" # noqa: S608
70+
+ " ON CONFLICT (uuid)" # noqa: S608
71+
+ " DO UPDATE" # noqa: S608
72+
+ " SET (session,expire)=(EXCLUDED.session, EXCLUDED.expire)",
7173
[key, data_encoded, data["created"], expire])

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from setuptools import setup
21
import os
32
import re
43

4+
from setuptools import setup
5+
56

67
with open(os.path.join(os.path.abspath(os.path.dirname(
78
__file__)), 'aiohttp_session', '__init__.py'), 'r', encoding='latin1') as fp:
@@ -14,6 +15,7 @@
1415
def read(f):
1516
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()
1617

18+
1719
install_requires = ['aiohttp>=3.0.1', 'typing_extensions>=3.7.4; python_version<"3.8"']
1820
extras_require = {
1921
'aioredis': ['aioredis>=1.0.0'],

0 commit comments

Comments
 (0)