-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(redis): make xadd fields use SupportsItems #10780
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
Conversation
This comment has been minimized.
This comment has been minimized.
Why? |
You're too fast :) I didn't finish to write the description correctly. That said, I just saw a discussion to drop types-redis, so not sure you continue to accept change to this typing. (btw, redis 5.x builtin typing is far to be usable due to redis/redis-py#2933) |
While I'm fine with replacing |
68430f5
to
b6226cb
Compare
This comment has been minimized.
This comment has been minimized.
b6226cb
to
36f7e95
Compare
This comment has been minimized.
This comment has been minimized.
b1b3164
to
dcc7dc4
Compare
98eed3a
to
3744db3
Compare
3744db3
to
44d786c
Compare
I propose another solution. |
44d786c
to
ab3152a
Compare
This comment has been minimized.
This comment has been minimized.
Hmm, redis-py seems to explicitly check for a dict: @sileht Can you give an example where type checkers have problems with the current annotations? |
FWIW, it does look to me like the current annotations we have are possibly the worst of both worlds. We don't get nice covariant types, since I'd also be curious for @sileht's use case where the current annotations are causing a problem, though; it's hard to solve a problem if we don't know exactly what the problem is. |
Currently, you can't write thing like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering @sileht's valid use case and the fact that we prefer false negatives over false positives, I think this change is the best we can do.
@sileht Could you add a comment before the fields
argument, something like "Only accepts dict objects, but for variance reasons we use a looser annotation." (Maybe you can come up with a better wording.)
Using an InvariantMapping is wrong, the type of each values of the dict can be different. This change uses a Protocol instead to match as much as possible the code: ``` if not isinstance(fields, dict) or len(fields) == 0: raise DataError("XADD fields must be a non-empty dict") for pair in fields.items(): pieces.extend(pair) ```
ab3152a
to
a3fab0c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This comment has been minimized.
This comment has been minimized.
d0b17c0
to
0d1ac89
Compare
This comment has been minimized.
This comment has been minimized.
Pyright is now unhappy because xadd doesn't have a return type. If I'm reading https://redis.io/commands/xadd/ right, it should return a str most of the time, but possibly None if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the easier solution :)
Oh I just ignored it for now. But if you have a better fix, feel free to push it :) |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Using an InvariantMapping is wrong, the type of each values of the dict
can be different.
This change uses the SupportsItems Protocol instead to match as much as possible the
code.