Skip to content

Commit

Permalink
Python: Address flake8 lint issues (valkey-io#3205)
Browse files Browse the repository at this point in the history
* Fix lint

Signed-off-by: Edward Liang <edward.liang@improving.com>
  • Loading branch information
edlng authored Feb 19, 2025
1 parent 2cd229f commit 7f386f0
Show file tree
Hide file tree
Showing 43 changed files with 2,281 additions and 1,351 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
flake8 . --count --max-complexity=12 --max-line-length=127 --statistics --extend-ignore=E230 --exclude=python/glide/protobuf,.env/*
- name: Lint python with black
if: always()
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ python-lint: .build/python_deps
black . --exclude python/glide/protobuf --exclude .env && \
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics \
--exclude=python/glide/protobuf,.env/* --extend-ignore=E230 && \
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 \
flake8 . --count --max-complexity=12 --max-line-length=127 \
--statistics --exclude=python/glide/protobuf,.env/* \
--extend-ignore=E230

Expand Down
16 changes: 10 additions & 6 deletions benchmarks/python/python_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import numpy as np
import redis.asyncio as redispy # type: ignore
from glide import (
GlideClientConfiguration,
GlideClusterClientConfiguration,
GlideClient,
GlideClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
Logger,
LogLevel,
NodeAddress,
Expand Down Expand Up @@ -290,10 +290,14 @@ async def main(
if clients_to_run == "all" or clients_to_run == "glide":
# Glide Socket
client_class = GlideClusterClient if is_cluster else GlideClient
config = GlideClusterClientConfiguration(
[NodeAddress(host=host, port=port)], use_tls=use_tls
) if is_cluster else GlideClientConfiguration(
[NodeAddress(host=host, port=port)], use_tls=use_tls
config = (
GlideClusterClientConfiguration(
[NodeAddress(host=host, port=port)], use_tls=use_tls
)
if is_cluster
else GlideClientConfiguration(
[NodeAddress(host=host, port=port)], use_tls=use_tls
)
)
clients = await create_clients(
client_count,
Expand Down
9 changes: 4 additions & 5 deletions examples/python/cluster_example.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import asyncio
from typing import List, Tuple, Optional
from typing import List, Optional, Tuple

from glide import AllNodes, ClosingError
from glide import ConnectionError as GlideConnectionError
from glide import (
AllNodes,
ClosingError,
ConnectionError as GlideConnectionError,
GlideClusterClient,
GlideClusterClientConfiguration,
InfoSection,
Logger,
LogLevel,
NodeAddress,
RequestError,
TimeoutError as GlideTimeoutError,
)
from glide import TimeoutError as GlideTimeoutError


async def create_client(
Expand Down
51 changes: 23 additions & 28 deletions examples/python/ft_example.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import asyncio
from typing import List, Tuple, Optional

from glide.async_commands.server_modules import glide_json as json
from glide.async_commands.server_modules import ft
from glide.constants import OK, FtSearchResponse, TEncodable

import uuid
from typing import List, Optional, Tuple

from glide import AllNodes, ClosingError
from glide import ConnectionError as GlideConnectionError
from glide import (
AllNodes,
ClosingError,
ConnectionError as GlideConnectionError,
GlideClusterClient,
GlideClusterClientConfiguration,
InfoSection,
Logger,
LogLevel,
NodeAddress,
RequestError,
TimeoutError as GlideTimeoutError,
)

from glide import TimeoutError as GlideTimeoutError
from glide.async_commands.server_modules import ft
from glide.async_commands.server_modules import glide_json as json
from glide.async_commands.server_modules.ft_options.ft_create_options import (
DataType,
DistanceMetricType,
Expand All @@ -34,11 +29,12 @@
VectorFieldAttributesHnsw,
VectorType,
)

from glide.async_commands.server_modules.ft_options.ft_search_options import (
FtSearchOptions,
ReturnField,
)
from glide.constants import OK, FtSearchResponse, TEncodable


async def create_client(
nodes_list: Optional[List[Tuple[str, int]]] = None
Expand Down Expand Up @@ -69,6 +65,7 @@ async def create_client(
)
return await GlideClusterClient.create(config)


async def app_logic(client: GlideClusterClient):
"""
Executes the main logic of the application, performing basic operations
Expand All @@ -84,24 +81,22 @@ async def app_logic(client: GlideClusterClient):
json_key2 = prefix + "2"
json_value1 = {"a": 11111, "b": 2, "c": 3}
json_value2 = {"a": 22222, "b": 2, "c": 3}
create_response = await ft.create(client, index,
schema=[
NumericField("$.a", "a"),
NumericField("$.b", "b"),
],
options=FtCreateOptions(DataType.JSON),
)
Logger.log(LogLevel.INFO, "app", f"Create response is = {create_response!r}") # 'OK'
create_response = await ft.create(
client,
index,
schema=[
NumericField("$.a", "a"),
NumericField("$.b", "b"),
],
options=FtCreateOptions(DataType.JSON),
)
Logger.log(
LogLevel.INFO, "app", f"Create response is = {create_response!r}"
) # 'OK'

# Create a json key.
assert (
await json.set(client, json_key1, "$", json.dumps(json_value1))
== OK
)
assert (
await json.set(client, json_key2, "$", json.dumps(json_value2))
== OK
)
assert await json.set(client, json_key1, "$", json.dumps(json_value1)) == OK
assert await json.set(client, json_key2, "$", json.dumps(json_value2)) == OK

# Search for the vector
search_response = await ft.search(client, index, "*", options=ft_search_options)
Expand Down
18 changes: 10 additions & 8 deletions examples/python/json_example.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import asyncio
from typing import List, Tuple, Optional

from glide.async_commands.server_modules import glide_json as json
from typing import List, Optional, Tuple

from glide import AllNodes, ClosingError
from glide import ConnectionError as GlideConnectionError
from glide import (
AllNodes,
ClosingError,
ConnectionError as GlideConnectionError,
GlideClusterClient,
GlideClusterClientConfiguration,
InfoSection,
Logger,
LogLevel,
NodeAddress,
RequestError,
TimeoutError as GlideTimeoutError,
)
from glide import TimeoutError as GlideTimeoutError
from glide.async_commands.server_modules import glide_json as json


async def create_client(
Expand Down Expand Up @@ -47,6 +45,7 @@ async def create_client(
)
return await GlideClusterClient.create(config)


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

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


async def exec_app_logic():
"""
Expand Down
6 changes: 3 additions & 3 deletions examples/python/standalone_example.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import asyncio
from typing import List, Tuple

from glide import ClosingError
from glide import ConnectionError as GlideConnectionError
from glide import (
ClosingError,
ConnectionError as GlideConnectionError,
GlideClient,
GlideClientConfiguration,
Logger,
LogLevel,
NodeAddress,
RequestError,
TimeoutError as GlideTimeoutError,
)
from glide import TimeoutError as GlideTimeoutError


async def create_client(
Expand Down
Loading

0 comments on commit 7f386f0

Please sign in to comment.