Skip to content

Commit cfe5f91

Browse files
committed
fix several pylint issues & bug KIKIMR-13478
ref:8856573 sync: https://proxy.sandbox.yandex-team.ru/2575333352
1 parent 5cde7c4 commit cfe5f91

File tree

37 files changed

+538
-564
lines changed

37 files changed

+538
-564
lines changed

examples/access-token-credentials/main.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def execute_query(session):
99
# statement. The either way to commit transaction is using `commit` method of `TxContext` object, which is
1010
# not recommended.
1111
return session.transaction().execute(
12-
'select 1 as cnt;',
12+
"select 1 as cnt;",
1313
commit_tx=True,
14-
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2)
14+
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2),
1515
)
1616

1717

@@ -22,9 +22,11 @@ def main():
2222
# because the specified access token can expire. For example,
2323
# Yandex.Cloud IAM token lifetime is limited by 12 hours.
2424
driver = ydb.Driver(
25-
endpoint=os.getenv('YDB_ENDPOINT'),
26-
database=os.getenv('YDB_DATABASE'),
27-
credentials=ydb.AccessTokenCredentials(os.getenv("YDB_ACCESS_TOKEN_CREDENTIALS")),
25+
endpoint=os.getenv("YDB_ENDPOINT"),
26+
database=os.getenv("YDB_DATABASE"),
27+
credentials=ydb.AccessTokenCredentials(
28+
os.getenv("YDB_ACCESS_TOKEN_CREDENTIALS")
29+
),
2830
)
2931

3032
# Start driver context manager.

examples/aio/driver_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55

66
async def describe_database():
7-
endpoint = os.getenv('YDB_ENDPOINT')
8-
database = os.getenv('YDB_DATABASE')
7+
endpoint = os.getenv("YDB_ENDPOINT")
8+
database = os.getenv("YDB_DATABASE")
99
driver = ydb.aio.Driver(
10-
endpoint=endpoint,
11-
database=database
10+
endpoint=endpoint, database=database
1211
) # Creating new database driver to execute queries
1312

1413
await driver.wait(timeout=10) # Wait until driver can execute calls
@@ -21,5 +20,6 @@ async def describe_database():
2120

2221
await driver.stop() # Stops driver and close all connections
2322

23+
2424
if __name__ == "__main__":
2525
asyncio.get_event_loop().run_until_complete(describe_database())

examples/aio/example_data.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
class Series(object):
5-
__slots__ = ('series_id', 'title', 'release_date', 'series_info')
5+
__slots__ = ("series_id", "title", "release_date", "series_info")
66

77
def __init__(self, series_id, title, release_date, series_info):
88
self.series_id = series_id
@@ -12,7 +12,7 @@ def __init__(self, series_id, title, release_date, series_info):
1212

1313

1414
class Season(object):
15-
__slots__ = ('series_id', 'season_id', 'title', 'first_aired', 'last_aired')
15+
__slots__ = ("series_id", "season_id", "title", "first_aired", "last_aired")
1616

1717
def __init__(self, series_id, season_id, title, first_aired, last_aired):
1818
self.series_id = series_id
@@ -23,7 +23,7 @@ def __init__(self, series_id, season_id, title, first_aired, last_aired):
2323

2424

2525
class Episode(object):
26-
__slots__ = ('series_id', 'season_id', 'episode_id', 'title', 'air_date')
26+
__slots__ = ("series_id", "season_id", "episode_id", "title", "air_date")
2727

2828
def __init__(self, series_id, season_id, episode_id, title, air_date):
2929
self.series_id = series_id
@@ -35,12 +35,20 @@ def __init__(self, series_id, season_id, episode_id, title, air_date):
3535

3636
def get_series_data():
3737
return [
38-
Series(1, "IT Crowd", "2006-02-03",
39-
"The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by "
40-
"Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry."),
41-
Series(2, "Silicon Valley", "2014-04-06",
42-
"Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and "
43-
"Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.")
38+
Series(
39+
1,
40+
"IT Crowd",
41+
"2006-02-03",
42+
"The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by "
43+
"Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry.",
44+
),
45+
Series(
46+
2,
47+
"Silicon Valley",
48+
"2014-04-06",
49+
"Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and "
50+
"Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.",
51+
),
4452
]
4553

4654

@@ -54,7 +62,7 @@ def get_seasons_data():
5462
Season(2, 2, "Season 2", "2015-04-12", "2015-06-14"),
5563
Season(2, 3, "Season 3", "2016-04-24", "2016-06-26"),
5664
Season(2, 4, "Season 4", "2017-04-23", "2017-06-25"),
57-
Season(2, 5, "Season 5", "2018-03-25", "2018-05-13")
65+
Season(2, 5, "Season 5", "2018-03-25", "2018-05-13"),
5866
]
5967

6068

examples/aio/read_table_examples.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,30 @@
66

77
async def create_tables():
88
from session_pool_example import main
9+
910
await main()
1011

1112

1213
async def insert_data():
1314
from transaction_example import main
15+
1416
await main()
1517

1618

1719
async def main():
1820
await create_tables()
1921
await insert_data()
20-
endpoint = os.getenv('YDB_ENDPOINT')
21-
database = os.getenv('YDB_DATABASE')
22-
driver = ydb.aio.Driver(
23-
endpoint=endpoint,
24-
database=database
25-
)
26-
pool = ydb.aio.SessionPool(
27-
driver,
28-
size=10 # Max number of available session
29-
)
22+
endpoint = os.getenv("YDB_ENDPOINT")
23+
database = os.getenv("YDB_DATABASE")
24+
driver = ydb.aio.Driver(endpoint=endpoint, database=database)
25+
pool = ydb.aio.SessionPool(driver, size=10) # Max number of available session
3026
session = await pool.acquire()
3127
async for sets in await session.read_table(database + "/episodes"):
3228
print(*[row[::] for row in sets.rows], sep="\n")
3329
await pool.release(session)
3430
await pool.stop()
3531
await driver.stop()
3632

37-
if __name__ == '__main__':
33+
34+
if __name__ == "__main__":
3835
asyncio.get_event_loop().run_until_complete(main())

examples/aio/session_pool_example.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
`air_date` Date,
3535
PRIMARY KEY (`series_id`, `season_id`, `episode_id`)
3636
)
37-
"""
37+
""",
3838
]
3939

4040

@@ -47,20 +47,21 @@ async def create_table(session, query):
4747

4848

4949
async def main():
50-
endpoint = os.getenv('YDB_ENDPOINT')
51-
database = os.getenv('YDB_DATABASE')
50+
endpoint = os.getenv("YDB_ENDPOINT")
51+
database = os.getenv("YDB_DATABASE")
5252
async with ydb.aio.Driver(endpoint=endpoint, database=database) as driver:
5353
await driver.wait(fail_fast=True)
5454

5555
async with ydb.aio.SessionPool(driver, size=10) as pool:
5656
coros = [ # Generating coroutines to create tables concurrently
57-
pool.retry_operation(create_table, query)
58-
for query in queries
57+
pool.retry_operation(create_table, query) for query in queries
5958
]
6059

6160
await asyncio.gather(*coros) # Run table creating concurrently
6261

63-
directory = await driver.scheme_client.list_directory(database) # Listing database to ensure that tables are created
62+
directory = await driver.scheme_client.list_directory(
63+
database
64+
) # Listing database to ensure that tables are created
6465
print("Items in database:")
6566
for child in directory.children:
6667
print(child.type, child.name)

examples/aio/transaction_example.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,31 @@
5858

5959
async def create_tables(): # Creating tables with session_pool_example
6060
from session_pool_example import main
61+
6162
await main()
6263

6364

6465
async def main():
6566
await create_tables()
66-
endpoint = os.getenv('YDB_ENDPOINT')
67-
database = os.getenv('YDB_DATABASE')
68-
driver = ydb.aio.Driver(
69-
endpoint=endpoint,
70-
database=database
71-
)
72-
pool = ydb.aio.SessionPool(
73-
driver,
74-
size=10 # Max number of available session
75-
)
67+
endpoint = os.getenv("YDB_ENDPOINT")
68+
database = os.getenv("YDB_DATABASE")
69+
driver = ydb.aio.Driver(endpoint=endpoint, database=database)
70+
pool = ydb.aio.SessionPool(driver, size=10) # Max number of available session
7671
session = await pool.acquire()
7772
prepared_query = await session.prepare(FillDataQuery.format(database))
7873
await session.transaction(ydb.SerializableReadWrite()).execute(
79-
prepared_query, {
80-
'$seriesData': example_data.get_series_data(),
81-
'$seasonsData': example_data.get_seasons_data(),
82-
'$episodesData': example_data.get_episodes_data(),
74+
prepared_query,
75+
{
76+
"$seriesData": example_data.get_series_data(),
77+
"$seasonsData": example_data.get_seasons_data(),
78+
"$episodesData": example_data.get_episodes_data(),
8379
},
84-
commit_tx=True
80+
commit_tx=True,
8581
)
8682
await pool.release(session)
8783
await driver.stop()
8884
await pool.stop()
8985

86+
9087
if __name__ == "__main__":
9188
asyncio.get_event_loop().run_until_complete(main())

examples/anonymous-credentials/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
def execute_query(session):
66
return session.transaction().execute(
7-
'select 1 as cnt;',
7+
"select 1 as cnt;",
88
commit_tx=True,
9-
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2)
9+
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2),
1010
)
1111

1212

1313
def main():
1414
driver = ydb.Driver(
15-
endpoint=os.getenv('YDB_ENDPOINT'),
16-
database=os.getenv('YDB_DATABASE'),
17-
credentials=ydb.AnonymousCredentials()
15+
endpoint=os.getenv("YDB_ENDPOINT"),
16+
database=os.getenv("YDB_DATABASE"),
17+
credentials=ydb.AnonymousCredentials(),
1818
)
1919

2020
with driver:

examples/asyncio/main.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,31 @@ 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(asyncio.wrap_future(session_holder), timeout=5)
13+
session = await asyncio.wait_for(
14+
asyncio.wrap_future(session_holder), timeout=5
15+
)
1416
except asyncio.TimeoutError:
1517
raise ydb.SessionPoolEmpty()
1618

1719
return await asyncio.wrap_future(
1820
session.transaction().async_execute(
19-
'select 1 as cnt;',
21+
"select 1 as cnt;",
2022
commit_tx=True,
21-
settings=ydb.BaseRequestSettings().with_timeout(3).with_operation_timeout(2)
23+
settings=ydb.BaseRequestSettings()
24+
.with_timeout(3)
25+
.with_operation_timeout(2),
2226
)
2327
)
2428

2529

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

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

examples/basic_example_v1/__main__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@
44
import logging
55

66

7-
if __name__ == '__main__':
7+
if __name__ == "__main__":
88
parser = argparse.ArgumentParser(
99
formatter_class=argparse.RawDescriptionHelpFormatter,
10-
description="""\033[92mYandex.Database examples binary.\x1b[0m\n""")
11-
parser.add_argument("-d", "--database", required=True, help="Name of the database to use")
10+
description="""\033[92mYandex.Database examples binary.\x1b[0m\n""",
11+
)
12+
parser.add_argument(
13+
"-d", "--database", required=True, help="Name of the database to use"
14+
)
1215
parser.add_argument("-e", "--endpoint", required=True, help="Endpoint url to use")
13-
parser.add_argument("-p", "--path", default='')
14-
parser.add_argument("-v", '--verbose', default=False, action='store_true')
16+
parser.add_argument("-p", "--path", default="")
17+
parser.add_argument("-v", "--verbose", default=False, action="store_true")
1518

1619
args = parser.parse_args()
1720

1821
if args.verbose:
19-
logger = logging.getLogger('kikimr.public.sdk.python.client.pool.Discovery')
22+
logger = logging.getLogger("kikimr.public.sdk.python.client.pool.Discovery")
2023
logger.setLevel(logging.INFO)
2124
logger.addHandler(logging.StreamHandler())
2225

0 commit comments

Comments
 (0)