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

fixed type hints of hash methods #154

Merged
merged 1 commit into from
Dec 17, 2024
Merged

Conversation

amirreza8002
Copy link
Contributor

@amirreza8002 amirreza8002 commented Dec 13, 2024

i do have one problem
hgetall() either returns a dict of bytes: dict[bytes, bytes], or an empty dict
python doesn't have any way to type hint empty dicts
so i either have to do what i did here and just type hint as dict, or do Union[dict[bytes, bytes], dict]

which do you think is better suited?

p.s: i'll provide examples of this methods' types in a coment

@amirreza8002
Copy link
Contributor Author

examples:
hset:

>>> v.hset("hash1", "foo", "bar")
1
>>> v.hset("hash2", mapping={"aa": "bb", "cc": "dd"})
2

hget:

>>> v.hget("hash1", "foo")
b'bar'
>>> v.hset("hash1", "baz", 2)
1
>>> v.hget("hash1", "baz")
b'2'

hdel:

>>> v.hdel("hash1", "foo")
1
>>> v.hdel("hash2", "aa", "cc")
2

hexists:

>>> v.hexists("hash1", "foo")
False
>>> v.hexists("hash1", "baz")
True

hgetall:

>>> v.hgetall("hash2")
{}
>>> v.hgetall("hash1")
{b'baz': b'2'}

hincrby:

>>> v.hincrby("hash1", "baz")
3
>>> v.hincrby("hash1", "baz", 4)
7

hincrbyfloat:

>>> v.hset("hash1", "foo", 2.2)
1
>>> v.hincrbyfloat("hash1", "foo", 4.1)
6.3

hkeys:

>>> v.hkeys("hash1")
[b'baz', b'foo']

hlen:

>>> v.hlen("hash1")
2

hsetnx:

>>> v.hsetnx("hash1", "foo", 1)
0
>>> v.hsetnx("hash1", "new", 1)
1

hmset:

>>> v.hmset("hash2", {"a": "b", "c": "d", "e": 3})
<python-input-23>:1: DeprecationWarning: Valkey.hmset() is deprecated. Use Valkey.hset() instead.
  v.hmset("hash2", {"a": "b", "c": "d", "e": 3})
True

hmget:

>>> v.hmget("hash2", ["a", "c", "e"])
[b'b', b'd', b'3']

hvals:

>>> v.hvals("hash2")
[b'b', b'd', b'3']

hstrlen:

>>> v.hstrlen("hash2", "a")
1

@codecov-commenter
Copy link

codecov-commenter commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.22%. Comparing base (d5bb6bf) to head (c006c85).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #154   +/-   ##
=======================================
  Coverage   76.22%   76.22%           
=======================================
  Files         130      130           
  Lines       33946    33946           
=======================================
  Hits        25877    25877           
  Misses       8069     8069           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@mkmkme mkmkme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

valkey/commands/core.py Show resolved Hide resolved
@mkmkme mkmkme merged commit ebdf9c9 into valkey-io:main Dec 17, 2024
93 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants