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

Case-insensitivity of keys doesn't extend to set operations #965

Open
Dreamsorcerer opened this issue Apr 11, 2024 · 3 comments
Open

Case-insensitivity of keys doesn't extend to set operations #965

Dreamsorcerer opened this issue Apr 11, 2024 · 3 comments
Assignees

Comments

@Dreamsorcerer
Copy link
Member

Would be nice to have this work correctly:

>>> d = multidict.CIMultiDict()
>>> d["CONTENT-LENGTH"] = "4"
>>> "Content-Length" in d.keys()
True
>>> {"Content-Length"} & d.keys()
set()  # Should get a result here
>>> {"CONTENT-LENGTH"} & d.keys()
{'CONTENT-LENGTH'}

I tried to do this in aiohttp to check if any of a set of headers is present.

@asvetlov asvetlov self-assigned this Dec 2, 2024
@asvetlov
Copy link
Member

asvetlov commented Dec 3, 2024

it seems that the feature request requires case insensitive set implemented first.
In turn, it raises additional questions:
What is the type of CISet() & set()? Should it be ci set or bare set? The same for set() & CISet()?

One possible solution could be returning CI Set for all binary operations if one of two arguments is also CI Set.

@asvetlov
Copy link
Member

asvetlov commented Dec 3, 2024

It seems that we cannot guarantee that CI Set is always returned; the type of a & b is type(a) for sets at least for their ABCs:

>>> frozenset(['a']) & {'b'}
frozenset()
>>> {'b'} & frozenset(['a'])
set()
>>> 

@Dreamsorcerer
Copy link
Member Author

Dreamsorcerer commented Dec 3, 2024

I think that can be changed by using __rand__, can't it?

But, I don't think it's necessary to have a CISet here, the main thing is just to ensure that the keys are returned. So, adding __add__/__or__ to KeysView and returning a set which contains the items in other which case-insensitively match keys in the KeysView should be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants