-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Underdocumented and partially untested behavior of set-like dict views #96408
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
Comments
The dict view docs intended cover these behaviors in the final sentence:
However, if you didn't already know the differences between concrete
As you say, the tests need to be beefed-up. They test registration with Would you like to submit a PR? |
Usage of set-like item dict views tested with operators and iterables. Co-authored-by: Piotr Kaznowski <[email protected]>
While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input. Co-authored-by: Filip Łajszczak <[email protected]>
While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input. Co-authored-by: Filip Łajszczak <[email protected]>
While using set operators, set-like views accept any iterable as the other operand, unlike sets which only accept sets as the input. Co-authored-by: Filip Łajszczak <[email protected]>
I've just reconsidered having an example and now think it should be taken out. It was correct to document that iterables were supported but we don't want an example to encourage it. It's too easy to fall into |
If I understand correctly, it (possibility of easy error) was the reason to make it impossible for sets. Maybe it could be possible, to replace keys example with items one with tuple of tuples instead of list of strings as the other operand. |
Aren't we heading into a more general discussion now (where my opinion would be: if an API is exposed, it should be accessible and documented; if, on the other hand, it's considered harmful, it shouldn't be exposed...)? Just for the background of this ticket (it's a real life scenario, so please bare with me): we had a bit of code in our codebase where we used a |
@caseneuve Just alternatives for your example:
|
Unlike sets, set-like dict view objects behave identical with both operator and non-operator versions of set operations.
In case of sets only non-operator versions accept any iterable as an argument, and one has to explicitly convert iterable to set to use operator on it. That's documented and tested.
Set-like dict view objects, however, accept any iterable after an operator.
As far as we were able to find that difference in behavior is not documented but is tested for keys but not for items. It's also reflected in the typeshed stubs.
The text was updated successfully, but these errors were encountered: