You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have checked there are no open bugs referencing the same bug or problem
Description
If counts is a Counter (which is a subclass of dict) from the collections module in the standard library, then count.update(...) and count |= ... have different semantics, specifically update() adds to the values while |= replaces the values. The code snippet below prints 2, but on accepting the suggested refactoring it would print 1.
While I understand the refactoring not preserving behavior in arbitrary subclasses, I would expect it to not break on things from the standard library.
Code snippet that reproduces issue
fromcollectionsimportCountercounts=Counter({'a': 1})
counts.update({'a': 1, 'b': 2})
# counts |= {'a': 1, 'b': 2}print(counts['a']) # prints 2 as is, 1 after refactor
Debug Information
IDE Version:
PyCharm Professional Edition 2023.2
Sourcery Version:
Sourcery 1.6.0
Operating system and Version:
Manjaro Linux
The text was updated successfully, but these errors were encountered:
Due to this I've downgraded this rule from a refactoring to a suggestion (meaning it doesn't get combined with other rules and needs individual consideration). This change will be in our next release.
Checklist
Description
If
counts
is aCounter
(which is a subclass ofdict
) from thecollections
module in the standard library, thencount.update(...)
andcount |= ...
have different semantics, specificallyupdate()
adds to the values while|=
replaces the values. The code snippet below prints 2, but on accepting the suggested refactoring it would print 1.While I understand the refactoring not preserving behavior in arbitrary subclasses, I would expect it to not break on things from the standard library.
Code snippet that reproduces issue
Debug Information
IDE Version:
PyCharm Professional Edition 2023.2
Sourcery Version:
Sourcery 1.6.0
Operating system and Version:
Manjaro Linux
The text was updated successfully, but these errors were encountered: