Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Using type() to compare types - cannot use class that has str as base class #856

Closed
netrix opened this issue Nov 23, 2020 · 2 comments
Closed
Labels
easy Good first PR enhancement help wanted resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.

Comments

@netrix
Copy link

netrix commented Nov 23, 2020

It's not possible to use StrEnum(str, Enum) object as a key because of following code: https://github.com/aio-libs/aioredis/blob/231d0418988fd870c3d26d60eec65e2fc13d0144/aioredis/util.py#L35

Unfortunately this code requires argument to by strictly str type instead of being a subclass of str.

What I'd like to achieve is following:

from enum import Enum

class StrEnum(str, Enum):
     AAA = "aaa"

# ....

rdb.hmget("key", StrEnum.AAA)
@seandstewart
Copy link
Collaborator

@netrix - Thanks for the submission!

I've implemented something similar here:

https://github.com/seandstewart/typical/blob/47a937fa1586c2b5bc0be6a6f89d06b089df3f3d/typic/util.py#L515-L535

If you have a moment to provide an implementation, I'd love to see a PR for this!

@seandstewart seandstewart added this to To do in Resuscitation via automation Nov 28, 2020
@seandstewart
Copy link
Collaborator

This issue should be resolved as of #891 - please feel free to pull in the latest master and test to ensure this is the case.

Resuscitation automation moved this from To do to Done Mar 19, 2021
@seandstewart seandstewart added the resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version. label Mar 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
easy Good first PR enhancement help wanted resolved-via-latest This indicates this issue is either resolved or invalid as of the latest version.
Projects
No open projects
Development

No branches or pull requests

2 participants