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
{{ message }}
Repository navigation
operator.rst mentioning or_ should also mention dict merge operators #141623
I wasn't sure if or_ applies also to dictionaries, but according to the trivial implementation, of course it does :). Anyway, I thought it would be nice to rephrase the above 2 parts of the document somehow - not sure exactly how to do phrase it myself.
Is the issue about "bitwise or" not being defined for dictionaries in this case?
No. The issue is that sphinx docs for operator.or_says:
Return the bitwise or of a and b.
It's not true. This might return a set union, or a logical or of symbolic expressions in some CAS, or something else. Docstring seems correct here:
>>> help(operator.or_)
Help on built-in function or_ in module _operator:
or_(a, b, /)
Same as a | b.
It's just a function analog of the corresponding expression. Same for and_, xor_, invert, truediv. Even for mul.
We might note, that for integers that means the bitwise or, or that for numbers operator.mul means multiplication. But I'm not sure if this worth to mention.
No. The problem is likely that "bitwise or" is usually used for integers, not for objects in general. Here, it would be better to talk about "binary or" in contrast to "logical or" (which we cannot override).
Urgh, I would have preferred the logical or to reflect the "logical" or in the sense of Python (with the or keyword and truthiness) and binary or for whatever else (binary since there are 2 operands). But if SymPy uses __or__ for logical expressions as well, let's just stick to a | b.
So the fix is to change "Return the bitwise or of a and b" to something like:
"Return the result of a | b."
This avoids the confusion since "bitwise" is too specific, and we let the | operator speak for itself (works for ints, sets, dicts, etc. based on their __or__ implementation).
Would that be satisfactory?
I think so (?) at least I think it's sufficient. People don't care what the operator is named from a theoretical PoV. Strictly speaking it is a "binary operator" (in the mathematical sense) but we don't need to be picky here. a | b will be sufficient.
Activity
skirpichev commentedon Nov 16, 2025
Good catch. This affects also e.g. and_ and xor. (Maybe more.) These operators are defined e.g. for sets.
I think something like "Return a | b" is fine.
picnixz commentedon Nov 16, 2025
Is the issue about "bitwise or" not being defined for dictionaries in this case? and that you want to have another word for this?
Yashp002 commentedon Nov 16, 2025
picnixz commentedon Nov 16, 2025
Your analysis is inccorrect. It is defined for dictionaries.
Yashp002 commentedon Nov 16, 2025
So is the main problem here that bitwise or isn't communicated in the docs/isn't immediately obvious to be functional for dictionary merging as well?
skirpichev commentedon Nov 16, 2025
No. The issue is that sphinx docs for
operator.or_says:It's not true. This might return a set union, or a logical or of symbolic expressions in some CAS, or something else. Docstring seems correct here:
It's just a function analog of the corresponding expression. Same for
and_,xor_,invert,truediv. Even formul.We might note, that for integers that means the bitwise or, or that for numbers
operator.mulmeans multiplication. But I'm not sure if this worth to mention.picnixz commentedon Nov 16, 2025
No. The problem is likely that "bitwise or" is usually used for integers, not for objects in general. Here, it would be better to talk about "binary or" in contrast to "logical or" (which we cannot override).
skirpichev commentedon Nov 16, 2025
SymPy uses
__or__()to represent logical or for expressions.picnixz commentedon Nov 16, 2025
Urgh, I would have preferred the logical or to reflect the "logical" or in the sense of Python (with the
orkeyword and truthiness) and binary or for whatever else (binary since there are 2 operands). But if SymPy uses__or__for logical expressions as well, let's just stick toa | b.1 remaining item
picnixz commentedon Nov 16, 2025
(@skirpichev no need for the labels if they affect all stable & in-dev versions)
Yashp002 commentedon Nov 16, 2025
So the fix is to change "Return the bitwise or of a and b" to something like:
"Return the result of
a | b."This avoids the confusion since "bitwise" is too specific, and we let the
|operator speak for itself (works for ints, sets, dicts, etc. based on their__or__implementation).Would that be satisfactory?
picnixz commentedon Nov 22, 2025
I think so (?) at least I think it's sufficient. People don't care what the operator is named from a theoretical PoV. Strictly speaking it is a "binary operator" (in the mathematical sense) but we don't need to be picky here.
a | bwill be sufficient.operator.rst: don't use bitwise keyword
doronbehar commentedon Nov 22, 2025
operator.rst: don't use bitwise keyword
operator.rst: don't use bitwise keyword
gh-141623: operator.rst: don't use term "bitwise" (GH-141846)
[3.13] gh-141623: operator.rst: don't use term "bitwise" (GH-141846) (G…
[3.14] gh-141623: Clarify operator function descriptions (GH-141846)
[3.15] gh-141623: Clarify operator function descriptions (GH-141846)
pythongh-141623: operator.rst: don't use term "bitwise" (pythonGH-141846