redis-py icon indicating copy to clipboard operation
redis-py copied to clipboard

Usage of hset not as expected

Open AlbertMoser opened this issue 2 years ago • 1 comments

Version: What redis-py and what redis version is the issue happening on? redis-py 4.2.2 / 4.3.1 python 3.9.5 redis (server side is not relevant here)

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure) Ubuntu 20.04

Description: Description of your issue, stack traces from errors and code that reproduces the issue I wanted to switch from hmset (deprecated) to hset. The parameters of hset look as follows:

def hset(
        self,
        name: str,
        key: Optional[str] = None,
        value: Optional[str] = None,
        mapping: Optional[dict] = None,
        items: Optional[list] = None,
    )

Concerning this, there are two issues I ran into:

  1. mypy complains when the function is called without defining values for key and value instead of
import redis

redis_client = redis.Redis(host='127.0.0.1', port=6379, decode_responses=True, db=1)
name = 'foo'
mapping = {'1': ['11', '22']}
redis_client.hset(name=name, mapping=mapping)

I have to call hset the following way

redis_client.hset(name=name, mapping=mapping, key=None, value=None)

even though the standard value for both of them is None. I would expect not having to assign values to key and value when I passed something for mapping.

  1. the keyword argument items is not recognized when calling the function
items = ['bar']
redis_client.hset(name=name, items=items)

I would expect that I can pass something to the function using items

Note: I tried to simplify the usage and it might be that it is not 100% correct.

AlbertMoser avatar May 18 '22 13:05 AlbertMoser

Any info on this?

jaceq avatar Jul 21 '22 12:07 jaceq

There is for sure some typing issue here, but I can't figure out what it actually is.

with redis.Redis() as r:
    r.hset("key", mapping={"thinga": "thingb"})

passes the type checking validation but

with redis.Redis() as r:
    r.hset("key", items=["thinga": "thingb"])

does not with the message

No overloads for "hset" match the provided arguments
  Argument types: (Literal['key'], list[str])).

They both work as expected at runtime though.

greyltc avatar Dec 15 '22 14:12 greyltc

This issue is marked stale. It will be closed in 30 days if it is not updated.

github-actions[bot] avatar Jan 15 '24 00:01 github-actions[bot]