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
cannot in-place update set with keys_view using |= #101478
Comments
|
Offhand, I don't think it was intended that |
Are you saying that |
|
@rhettinger I think with this
you're targeting the following sencence from the docs:
So it actually says "sets", not mentioning "frozensets". Obviously frozensets work, but a literal In any other case I expect at least an error, an never for the left hand side to refer to a different object after the operation. |
That is an incorrect reading. The operator arguments are required to be either a set, frozenset, or one of their subclasses. This was a deliberate design choice. The choice was present in the original sets.py implementation and in the C implementation. We specifically test for this behavior.
In principle, I agree. However, I don't see a way to fix the dict view implementations. In general,
I'm going to close this as a known limitation. Fortunately, there is a simple workaround. Just use |
Bug report
Updating a set with an instance of keys_view using the
|=operator results in a new object, instead of an updated one.This is unlike updating a set with an other set or a frozenset using the same operator, or using the update method. Given the docs I expect all cases to behave the same, and expect the following snippet to not fail. Yet it fails.
Note that a
keys_viewis not a set, but it does implement the AbstracrSet api, so thatisinstance(<keys_view inst>, AbstractSet)isTrue.Your environment
The text was updated successfully, but these errors were encountered: