This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: True%2 is True
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, h.venev
Priority: normal Keywords:

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:25adminsetgithub: 70214
2016-01-07 09:37:44h.venevsetmessages: + msg257681
2016-01-07 09:13:08h.venevsetmessages: + msg257680
2016-01-07 08:34:35SilentGhostsetstatus: open -> closed
resolution: not a bug
messages: + msg257678
2016-01-07 08:02:23h.venevsetstatus: closed -> open
resolution: not a bug -> (no value)
messages: + msg257677
2016-01-06 18:52:58SilentGhostsetstatus: open -> closed

type: behavior

nosy: + SilentGhost
messages: + msg257631
resolution: not a bug
stage: resolved
2016-01-06 18:38:29h.venevsettitle: True%2==True -> True%2 is True
2016-01-06 18:38:14h.venevcreate