Skip to content

Commit fd07bef

Browse files
[aiohttp] Revert globals (#9798)
1 parent 07f447e commit fd07bef

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

frameworks/Python/aiohttp/app/views.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,19 @@
1-
import random
21
from operator import attrgetter, itemgetter
32
from pathlib import Path
3+
from random import randint, sample
44

5-
import aiohttp.web
65
import jinja2
7-
import sqlalchemy
8-
import sqlalchemy.orm
9-
import orjson
10-
11-
from . import models
12-
13-
# In current versions of Python (tested 3.9 and 3.12), from ... import ...
14-
# creates variables that are atleast 4x slower to reference:
15-
# > python3 -m timeit 'from random import sample' 'sample'
16-
# 500000 loops, best of 5: 823 nsec per loop
17-
# > python3 -m timeit 'import random' 'random.sample'
18-
# 2000000 loops, best of 5: 161 nsec per loop
19-
# > python3 -m timeit 'import random; sample = random.sample' 'sample'
20-
# 2000000 loops, best of 5: 161 nsec per loop
21-
dumps = orjson.dumps
22-
randint = random.randint
23-
sample = random.sample
24-
Response = aiohttp.web.Response
25-
select = sqlalchemy.select
26-
flag_modified = sqlalchemy.orm.attributes.flag_modified
27-
Fortune = models.Fortune
28-
World = models.World
6+
from aiohttp.web import Response
7+
from orjson import dumps
8+
from sqlalchemy import bindparam, select
9+
from sqlalchemy.orm.attributes import flag_modified
10+
11+
from .models import Fortune, World
2912

3013
ADDITIONAL_FORTUNE_ORM = Fortune(id=0, message='Additional fortune added at request time.')
3114
ADDITIONAL_FORTUNE_ROW = {'id': 0, 'message': 'Additional fortune added at request time.'}
3215
READ_ROW_SQL = 'SELECT "randomnumber", "id" FROM "world" WHERE id = $1'
33-
READ_SELECT_ORM = select(World.randomnumber).where(World.id == sqlalchemy.bindparam("id"))
16+
READ_SELECT_ORM = select(World.randomnumber).where(World.id == bindparam("id"))
3417
READ_FORTUNES_ORM = select(Fortune.id, Fortune.message)
3518
WRITE_ROW_SQL = 'UPDATE "world" SET "randomnumber"=$2 WHERE id=$1'
3619

0 commit comments

Comments
 (0)