Issue 26026: True%2 is True (original) (raw)

Created on 2016-01-06 18:38 by h.venev, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg257629 - (view) Author: Hristo Venev (h.venev) * Date: 2016-01-06 18:38
Should be 1. This comes from the (a%b=a if a<b) optimization. Let's be consistent with all other arithmetic operations.
msg257631 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-01-06 18:52
Arithmetic operations should not be used with booleans, they happen to work due to boolean bean a subclass of int.
msg257677 - (view) Author: Hristo Venev (h.venev) * Date: 2016-01-07 08:02
OK. class A(int): pass a=A(1) b=A(2) print(type(a*b), type(a+b), type(a-b), type(a**b), type(a^b), type(a&b), type(a|b), type(a//b), type(a%b))
msg257678 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-01-07 08:34
Hristo, python is a duck typing language. You should not have to care about the type of a variable as long as it does what's intended. Seeking consistency where none is required will just end up being huge waste of everyone's time. If you're so convinced in the rightness of your opinion, please take it to python-ideas mailing list and have it discussed there first before re-opening issue in the future.
msg257680 - (view) Author: Hristo Venev (h.venev) * Date: 2016-01-07 09:13
One last thing: type(a%b) is A, type(b%a) is int.
msg257681 - (view) Author: Hristo Venev (h.venev) * Date: 2016-01-07 09:37
type( A(1) % A(2) ) is A type( A(1) % A(-2) ) is int type( A(-1) % A(-2) ) is A type( A(2) % A(1) ) is int type( A(1) % A(2**30+2) ) is A type( A(2**30+1) % A(2**30+2) ) is int type( A(2**15+1) % A(2**15+2) ) is (A if 64bit else int)
History
Date User Action Args
2022-04-11 14:58:25 admin set github: 70214
2016-01-07 09:37:44 h.venev set messages: +
2016-01-07 09:13:08 h.venev set messages: +
2016-01-07 08:34:35 SilentGhost set status: open -> closedresolution: not a bugmessages: +
2016-01-07 08:02:23 h.venev set status: closed -> openresolution: not a bug -> (no value)messages: +
2016-01-06 18:52:58 SilentGhost set status: open -> closedtype: behaviornosy: + SilentGhostmessages: + resolution: not a bugstage: resolved
2016-01-06 18:38:29 h.venev set title: True%2==True -> True%2 is True
2016-01-06 18:38:14 h.venev create