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

SortedDict |= incorrect behavior #169

Closed
bulaiden opened this issue Apr 28, 2021 · 3 comments · Fixed by #171
Closed

SortedDict |= incorrect behavior #169

bulaiden opened this issue Apr 28, 2021 · 3 comments · Fixed by #171

Comments

@bulaiden
Copy link

SortedDict implementation of |= (augmented assignment union operator) is currently incorrect.
For d1 |= d2, it will not add keys of d2 that are missing in d1.

In comparison, the regular union operator d1 | d2 works fine.

@grantjenks
Copy link
Owner

Oops, yes, that’s a bug. The code is currently using “|=“ inherited from dict which means the internal indexes aren’t updated.

I think “|=“ is similar to “update” which may be a workaround until this is fixed.

@grantjenks
Copy link
Owner

In PEP 584, there’s a good reference implementation based on update(): https://www.python.org/dev/peps/pep-0584/#reference-implementation . That code would likely work for SortedDict with appropriate tests added.

grantjenks added a commit that referenced this issue May 16, 2021
Implement SortedDict methods: __or__, __ror__, and __ior__ (#171)

Fixes #169 .
@grantjenks
Copy link
Owner

Released in 2.4.0 to PyPI

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

Successfully merging a pull request may close this issue.

2 participants