Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PYTHON: Json.nummultby update #2578

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/python/glide/async_commands/server_modules/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ async def nummultby(
key: TEncodable,
path: TEncodable,
number: Union[int, float],
) -> Optional[bytes]:
) -> bytes:
"""
Multiplies the JSON value(s) at the specified `path` by `number` within the JSON document stored at `key`.

Expand All @@ -744,7 +744,7 @@ async def nummultby(
number (Union[int, float]): The number to multiply by.

Returns:
Optional[bytes]:
bytes:
For JSONPath (`path` starts with `$`):
Returns a bytes string representation of an array of bulk strings, indicating the new values after multiplication for each matched `path`.
If a value is not a number, its corresponding return value will be `null`.
Expand All @@ -767,7 +767,7 @@ async def nummultby(
"""
args = ["JSON.NUMMULTBY", key, path, str(number)]

return cast(Optional[bytes], await client.custom_command(args))
return cast(bytes, await client.custom_command(args))


async def objlen(
Expand Down
4 changes: 4 additions & 0 deletions python/python/tests/tests_server_modules/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,10 @@ async def test_json_nummultby(self, glide_client: TGlideClient):
result = await json.get(glide_client, key, "$..key1") # type: ignore
assert result == b"[-16500,[140,175],1380]"

# Check 'null' in legacy
with pytest.raises(RequestError):
await json.nummultby(glide_client, key, ".key7", 5)

# Check for non-existent path in legacy
with pytest.raises(RequestError):
await json.nummultby(glide_client, key, ".key10", 51)
Expand Down
Loading