Preferences

That’s not “the normal way”, it’s just the case when the LHS is immutable.

This behavior is congruent to C++ and it’s documented and idiomatic.

It’d be weird if the in-place operator deeply copied the LHS, and problematic for a garbage-collected language in high throughput applications.


> That’s not “the normal way”, it’s just the case when the LHS is immutable.

It’s the default behaviour of |= if you override |, you need to specifically override |= to do otherwise.

> This behavior is congruent to C++

An excellent reason to do something else in and of itself.

> it’s documented and idiomatic.

Documenting a trap does not make it less of a trap. Innocently replacing | by |= induces a massive behavioural change which the user has little reason to expect, and which can easily lead to bugs due to mutating shared data.

> It’d be weird if the in-place operator deeply copied the LHS

I see you understand neither Python nor the behaviour of the | operator.

> problematic for a garbage-collected language in high throughput applications.

dict.update exists, if you specifically need to update the LHS in place it works just fine.

This item has no comments currently.

Keyboard Shortcuts

Story Lists

j
Next story
k
Previous story
Shift+j
Last story
Shift+k
First story
o Enter
Go to story URL
c
Go to comments
u
Go to author

Navigation

Shift+t
Go to top stories
Shift+n
Go to new stories
Shift+b
Go to best stories
Shift+a
Go to Ask HN
Shift+s
Go to Show HN

Miscellaneous

?
Show this modal