Skip to content

Commit 7f386f0

Browse files
authored
Python: Address flake8 lint issues (valkey-io#3205)
* Fix lint Signed-off-by: Edward Liang <edward.liang@improving.com>
1 parent 2cd229f commit 7f386f0

Some content is hidden

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

43 files changed

+2281
-1351
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ jobs:
222222
# stop the build if there are Python syntax errors or undefined names
223223
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
224224
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
225-
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
225+
flake8 . --count --max-complexity=12 --max-line-length=127 --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
226226
227227
- name: Lint python with black
228228
if: always()

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ python-lint: .build/python_deps
4343
black . --exclude python/glide/protobuf --exclude .env && \
4444
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics \
4545
--exclude=python/glide/protobuf,.env/* --extend-ignore=E230 && \
46-
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 \
46+
flake8 . --count --max-complexity=12 --max-line-length=127 \
4747
--statistics --exclude=python/glide/protobuf,.env/* \
4848
--extend-ignore=E230
4949

benchmarks/python/python_benchmark.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import numpy as np
1717
import redis.asyncio as redispy # type: ignore
1818
from glide import (
19-
GlideClientConfiguration,
20-
GlideClusterClientConfiguration,
2119
GlideClient,
20+
GlideClientConfiguration,
2221
GlideClusterClient,
22+
GlideClusterClientConfiguration,
2323
Logger,
2424
LogLevel,
2525
NodeAddress,
@@ -290,10 +290,14 @@ async def main(
290290
if clients_to_run == "all" or clients_to_run == "glide":
291291
# Glide Socket
292292
client_class = GlideClusterClient if is_cluster else GlideClient
293-
config = GlideClusterClientConfiguration(
294-
[NodeAddress(host=host, port=port)], use_tls=use_tls
295-
) if is_cluster else GlideClientConfiguration(
296-
[NodeAddress(host=host, port=port)], use_tls=use_tls
293+
config = (
294+
GlideClusterClientConfiguration(
295+
[NodeAddress(host=host, port=port)], use_tls=use_tls
296+
)
297+
if is_cluster
298+
else GlideClientConfiguration(
299+
[NodeAddress(host=host, port=port)], use_tls=use_tls
300+
)
297301
)
298302
clients = await create_clients(
299303
client_count,

examples/python/cluster_example.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import asyncio
2-
from typing import List, Tuple, Optional
2+
from typing import List, Optional, Tuple
33

4+
from glide import AllNodes, ClosingError
5+
from glide import ConnectionError as GlideConnectionError
46
from glide import (
5-
AllNodes,
6-
ClosingError,
7-
ConnectionError as GlideConnectionError,
87
GlideClusterClient,
98
GlideClusterClientConfiguration,
109
InfoSection,
1110
Logger,
1211
LogLevel,
1312
NodeAddress,
1413
RequestError,
15-
TimeoutError as GlideTimeoutError,
1614
)
15+
from glide import TimeoutError as GlideTimeoutError
1716

1817

1918
async def create_client(

examples/python/ft_example.py

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
import asyncio
2-
from typing import List, Tuple, Optional
3-
4-
from glide.async_commands.server_modules import glide_json as json
5-
from glide.async_commands.server_modules import ft
6-
from glide.constants import OK, FtSearchResponse, TEncodable
7-
82
import uuid
3+
from typing import List, Optional, Tuple
94

5+
from glide import AllNodes, ClosingError
6+
from glide import ConnectionError as GlideConnectionError
107
from glide import (
11-
AllNodes,
12-
ClosingError,
13-
ConnectionError as GlideConnectionError,
148
GlideClusterClient,
159
GlideClusterClientConfiguration,
1610
InfoSection,
1711
Logger,
1812
LogLevel,
1913
NodeAddress,
2014
RequestError,
21-
TimeoutError as GlideTimeoutError,
2215
)
23-
16+
from glide import TimeoutError as GlideTimeoutError
17+
from glide.async_commands.server_modules import ft
18+
from glide.async_commands.server_modules import glide_json as json
2419
from glide.async_commands.server_modules.ft_options.ft_create_options import (
2520
DataType,
2621
DistanceMetricType,
@@ -34,11 +29,12 @@
3429
VectorFieldAttributesHnsw,
3530
VectorType,
3631
)
37-
3832
from glide.async_commands.server_modules.ft_options.ft_search_options import (
3933
FtSearchOptions,
4034
ReturnField,
4135
)
36+
from glide.constants import OK, FtSearchResponse, TEncodable
37+
4238

4339
async def create_client(
4440
nodes_list: Optional[List[Tuple[str, int]]] = None
@@ -69,6 +65,7 @@ async def create_client(
6965
)
7066
return await GlideClusterClient.create(config)
7167

68+
7269
async def app_logic(client: GlideClusterClient):
7370
"""
7471
Executes the main logic of the application, performing basic operations
@@ -84,24 +81,22 @@ async def app_logic(client: GlideClusterClient):
8481
json_key2 = prefix + "2"
8582
json_value1 = {"a": 11111, "b": 2, "c": 3}
8683
json_value2 = {"a": 22222, "b": 2, "c": 3}
87-
create_response = await ft.create(client, index,
88-
schema=[
89-
NumericField("$.a", "a"),
90-
NumericField("$.b", "b"),
91-
],
92-
options=FtCreateOptions(DataType.JSON),
93-
)
94-
Logger.log(LogLevel.INFO, "app", f"Create response is = {create_response!r}") # 'OK'
84+
create_response = await ft.create(
85+
client,
86+
index,
87+
schema=[
88+
NumericField("$.a", "a"),
89+
NumericField("$.b", "b"),
90+
],
91+
options=FtCreateOptions(DataType.JSON),
92+
)
93+
Logger.log(
94+
LogLevel.INFO, "app", f"Create response is = {create_response!r}"
95+
) # 'OK'
9596

9697
# Create a json key.
97-
assert (
98-
await json.set(client, json_key1, "$", json.dumps(json_value1))
99-
== OK
100-
)
101-
assert (
102-
await json.set(client, json_key2, "$", json.dumps(json_value2))
103-
== OK
104-
)
98+
assert await json.set(client, json_key1, "$", json.dumps(json_value1)) == OK
99+
assert await json.set(client, json_key2, "$", json.dumps(json_value2)) == OK
105100

106101
# Search for the vector
107102
search_response = await ft.search(client, index, "*", options=ft_search_options)

examples/python/json_example.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import asyncio
2-
from typing import List, Tuple, Optional
3-
4-
from glide.async_commands.server_modules import glide_json as json
2+
from typing import List, Optional, Tuple
53

4+
from glide import AllNodes, ClosingError
5+
from glide import ConnectionError as GlideConnectionError
66
from glide import (
7-
AllNodes,
8-
ClosingError,
9-
ConnectionError as GlideConnectionError,
107
GlideClusterClient,
118
GlideClusterClientConfiguration,
129
InfoSection,
1310
Logger,
1411
LogLevel,
1512
NodeAddress,
1613
RequestError,
17-
TimeoutError as GlideTimeoutError,
1814
)
15+
from glide import TimeoutError as GlideTimeoutError
16+
from glide.async_commands.server_modules import glide_json as json
1917

2018

2119
async def create_client(
@@ -47,6 +45,7 @@ async def create_client(
4745
)
4846
return await GlideClusterClient.create(config)
4947

48+
5049
async def app_logic(client: GlideClusterClient):
5150
"""
5251
Executes the main logic of the application, performing basic operations
@@ -63,7 +62,10 @@ async def app_logic(client: GlideClusterClient):
6362
Logger.log(LogLevel.INFO, "app", f"Set response is = {set_response!r}") # 'OK'
6463

6564
get_response = await json.get(client, "key", "$")
66-
Logger.log(LogLevel.INFO, "app", f"Get response is = {get_response.decode()!r}") # "[{\"a\":1.0,\"b\":2}]"
65+
Logger.log(
66+
LogLevel.INFO, "app", f"Get response is = {get_response.decode()!r}"
67+
) # "[{\"a\":1.0,\"b\":2}]"
68+
6769

6870
async def exec_app_logic():
6971
"""

examples/python/standalone_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import asyncio
22
from typing import List, Tuple
33

4+
from glide import ClosingError
5+
from glide import ConnectionError as GlideConnectionError
46
from glide import (
5-
ClosingError,
6-
ConnectionError as GlideConnectionError,
77
GlideClient,
88
GlideClientConfiguration,
99
Logger,
1010
LogLevel,
1111
NodeAddress,
1212
RequestError,
13-
TimeoutError as GlideTimeoutError,
1413
)
14+
from glide import TimeoutError as GlideTimeoutError
1515

1616

1717
async def create_client(

0 commit comments

Comments
 (0)