Skip to content

Commit a142e80

Browse files
authored
Merge pull request #213 from ydb-platform/black-up-line-length
use line-length=120 for better code readability
2 parents df3a7fa + ba6c081 commit a142e80

File tree

83 files changed

+513
-1608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+513
-1608
lines changed

examples/_sqlalchemy_example/example.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def simple_select(conn):
2424

2525

2626
def simple_insert(conn):
27-
stm = Episodes.__table__.insert().values(
28-
series_id=3, season_id=6, episode_id=1, title="TBD"
29-
)
27+
stm = Episodes.__table__.insert().values(series_id=3, season_id=6, episode_id=1, title="TBD")
3028
conn.execute(stm)
3129

3230

@@ -51,9 +49,7 @@ def test_types(conn):
5149
conn.execute(stm)
5250

5351
# GROUP BY
54-
stm = sa.select(types_tb.c.str, sa.func.max(types_tb.c.num)).group_by(
55-
types_tb.c.str
56-
)
52+
stm = sa.select(types_tb.c.str, sa.func.max(types_tb.c.num)).group_by(types_tb.c.str)
5753
rs = conn.execute(stm)
5854
for x in rs:
5955
print(x)
@@ -171,9 +167,9 @@ def run_example_core(engine):
171167
simple_insert(conn)
172168

173169
# simple join
174-
stm = sa.select(
175-
[Episodes.__table__.join(Series, Episodes.series_id == Series.series_id)]
176-
).where(sa.and_(Series.series_id == 1, Episodes.season_id == 1))
170+
stm = sa.select([Episodes.__table__.join(Series, Episodes.series_id == Series.series_id)]).where(
171+
sa.and_(Series.series_id == 1, Episodes.season_id == 1)
172+
)
177173
rs = conn.execute(stm)
178174
for row in rs:
179175
print(f"{row.series_title}({row.episode_id}): {row.title}")

examples/access-token-credentials/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def main():
2424
driver = ydb.Driver(
2525
endpoint=os.getenv("YDB_ENDPOINT"),
2626
database=os.getenv("YDB_DATABASE"),
27-
credentials=ydb.AccessTokenCredentials(
28-
os.getenv("YDB_ACCESS_TOKEN_CREDENTIALS")
29-
),
27+
credentials=ydb.AccessTokenCredentials(os.getenv("YDB_ACCESS_TOKEN_CREDENTIALS")),
3028
)
3129

3230
# Start driver context manager.

examples/aio/driver_example.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
async def describe_database():
77
endpoint = os.getenv("YDB_ENDPOINT")
88
database = os.getenv("YDB_DATABASE")
9-
driver = ydb.aio.Driver(
10-
endpoint=endpoint, database=database
11-
) # Creating new database driver to execute queries
9+
driver = ydb.aio.Driver(endpoint=endpoint, database=database) # Creating new database driver to execute queries
1210

1311
await driver.wait(timeout=10) # Wait until driver can execute calls
1412

examples/asyncio/main.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,23 @@ async def execute_query(pool):
1010
with pool.async_checkout() as session_holder:
1111
try:
1212
# wait for the session checkout to complete.
13-
session = await asyncio.wait_for(
14-
asyncio.wrap_future(session_holder), timeout=5
15-
)
13+
session = await asyncio.wait_for(asyncio.wrap_future(session_holder), timeout=5)
1614
except asyncio.TimeoutError:
1715
raise ydb.SessionPoolEmpty()
1816

1917
return await asyncio.wrap_future(
2018
session.transaction().async_execute(
2119
"select 1 as cnt;",
2220
commit_tx=True,
23-
settings=ydb.BaseRequestSettings()
24-
.with_timeout(3)
25-
.with_operation_timeout(2),
21+
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2),
2622
)
2723
)
2824

2925

3026
async def main():
31-
with ydb.Driver(
32-
endpoint=os.getenv("YDB_ENDPOINT"), database=os.getenv("YDB_DATABASE")
33-
) as driver:
27+
with ydb.Driver(endpoint=os.getenv("YDB_ENDPOINT"), database=os.getenv("YDB_DATABASE")) as driver:
3428
# Wait for the driver to become active for requests.
35-
await asyncio.wait_for(
36-
asyncio.wrap_future(driver.async_wait(fail_fast=True)), timeout=5
37-
)
29+
await asyncio.wait_for(asyncio.wrap_future(driver.async_wait(fail_fast=True)), timeout=5)
3830

3931
# Create the session pool instance to manage YDB session.
4032
session_pool = ydb.SessionPool(driver)

examples/basic_example_v1/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
formatter_class=argparse.RawDescriptionHelpFormatter,
1010
description="""\033[92mYandex.Database examples binary.\x1b[0m\n""",
1111
)
12-
parser.add_argument(
13-
"-d", "--database", required=True, help="Name of the database to use"
14-
)
12+
parser.add_argument("-d", "--database", required=True, help="Name of the database to use")
1513
parser.add_argument("-e", "--endpoint", required=True, help="Endpoint url to use")
1614
parser.add_argument("-p", "--path", default="")
1715
parser.add_argument("-v", "--verbose", default=False, action="store_true")

examples/cloud-function-trivial-example/index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
import ydb
33

44
# create driver in global space.
5-
driver = ydb.Driver(
6-
endpoint=os.getenv("YDB_ENDPOINT"), database=os.getenv("YDB_DATABASE")
7-
)
5+
driver = ydb.Driver(endpoint=os.getenv("YDB_ENDPOINT"), database=os.getenv("YDB_DATABASE"))
86
# Wait for the driver to become active for requests.
97
driver.wait(fail_fast=True, timeout=5)
108
# Create the session pool instance to manage YDB sessions.

examples/pagination/__main__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
formatter_class=argparse.RawDescriptionHelpFormatter,
1010
description="""\033[92mYandex.Database example pagination.\x1b[0m\n""",
1111
)
12-
parser.add_argument(
13-
"-d", "--database", required=True, help="Name of the database to use"
14-
)
12+
parser.add_argument("-d", "--database", required=True, help="Name of the database to use")
1513
parser.add_argument("-e", "--endpoint", required=True, help="Endpoint url to use")
1614
parser.add_argument("-p", "--path", default="", help="Base path for tables")
1715

examples/reservations-bot-demo/cloud_function/controller.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ class Controller(object):
1616
def __init__(self, storage: Storage):
1717
self._storage = storage
1818

19-
def _find_available_table_id(
20-
self, request: ReservationCreateRequest
21-
) -> typing.Optional[int]:
19+
def _find_available_table_id(self, request: ReservationCreateRequest) -> typing.Optional[int]:
2220
table_ids = set(self._storage.list_table_ids(cnt=request.cnt))
23-
reserved_table_ids = set(
24-
self._storage.find_reserved_table_ids(cnt=request.cnt, dt=request.dt)
25-
)
21+
reserved_table_ids = set(self._storage.find_reserved_table_ids(cnt=request.cnt, dt=request.dt))
2622
for table_id in table_ids.difference(reserved_table_ids):
2723
return table_id
2824

29-
def maybe_create_reservation(
30-
self, request: ReservationCreateRequest
31-
) -> ReservationCreateResponse:
25+
def maybe_create_reservation(self, request: ReservationCreateRequest) -> ReservationCreateResponse:
3226
table_id = self._find_available_table_id(request)
3327
if table_id is None:
3428
logging.warning("reservation failed")
@@ -47,16 +41,11 @@ def maybe_create_reservation(
4741
logging.warning(f"failed to reserve a table due to {repr(e)}")
4842
return ReservationCreateResponse(success=False)
4943

50-
def maybe_cancel_reservation(
51-
self, request: ReservationCancelRequest
52-
) -> ReservationCancelResponse:
44+
def maybe_cancel_reservation(self, request: ReservationCancelRequest) -> ReservationCancelResponse:
5345
try:
5446
self._storage.delete_reservation(phone=request.phone, dt=request.dt)
5547
logging.warning(f"reservation {request.phone} {request.dt} cancelled")
5648
return ReservationCancelResponse(success=True)
5749
except Exception as e:
58-
logging.warning(
59-
f"failed to cancel reservation for {request.phone} "
60-
f"{request.dt} due to {repr(e)}"
61-
)
50+
logging.warning(f"failed to cancel reservation for {request.phone} " f"{request.dt} due to {repr(e)}")
6251
return ReservationCancelResponse(success=False)

examples/reservations-bot-demo/cloud_function/storage.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def transaction(session):
2626
tables = session_pool.retry_operation_sync(transaction)
2727
return list(map(lambda x: getattr(x, "table_id"), tables))
2828

29-
def find_reserved_table_ids(
30-
self, *, cnt: int, dt: datetime.datetime
31-
) -> typing.List[int]:
29+
def find_reserved_table_ids(self, *, cnt: int, dt: datetime.datetime) -> typing.List[int]:
3230
query = f"""PRAGMA TablePathPrefix("{self._database}");
3331
DECLARE $dt AS DateTime;
3432
DECLARE $reservation_period_minutes AS Int32;

examples/reservations-bot-demo/cloud_function/utils.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,17 @@ def make_driver_config(endpoint, database, path):
1313

1414

1515
@contextlib.contextmanager
16-
def session_pool_context(
17-
driver_config: ydb.DriverConfig, size=1, workers_threads_count=1
18-
):
16+
def session_pool_context(driver_config: ydb.DriverConfig, size=1, workers_threads_count=1):
1917
with ydb.Driver(driver_config) as driver:
2018
try:
2119
logging.info("connecting to the database")
2220
driver.wait(timeout=15)
2321
except TimeoutError:
2422
logging.critical(
25-
f"connection failed\n"
26-
f"last reported errors by discovery: {driver.discovery_debug_details()}"
23+
f"connection failed\n" f"last reported errors by discovery: {driver.discovery_debug_details()}"
2724
)
2825
raise
29-
with ydb.SessionPool(
30-
driver, size=size, workers_threads_count=workers_threads_count
31-
) as session_pool:
26+
with ydb.SessionPool(driver, size=size, workers_threads_count=workers_threads_count) as session_pool:
3227
try:
3328
yield session_pool
3429
except Exception as e:

0 commit comments

Comments
 (0)