Skip to content

True%2 is True #70214

Closed
Closed

Description

@hvenev
mannequin
BPO 26026
Nosy @hvenev

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-01-07.08:34:35.398>
created_at = <Date 2016-01-06.18:38:13.990>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'True%2 is True'
updated_at = <Date 2016-01-07.09:37:44.465>
user = 'https://github.com/hvenev'

bugs.python.org fields:

activity = <Date 2016-01-07.09:37:44.465>
actor = 'h.venev'
assignee = 'none'
closed = True
closed_date = <Date 2016-01-07.08:34:35.398>
closer = 'SilentGhost'
components = ['Interpreter Core']
creation = <Date 2016-01-06.18:38:13.990>
creator = 'h.venev'
dependencies = []
files = []
hgrepos = []
issue_num = 26026
keywords = []
message_count = 6.0
messages = ['257629', '257631', '257677', '257678', '257680', '257681']
nosy_count = 2.0
nosy_names = ['SilentGhost', 'h.venev']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue26026'
versions = ['Python 3.5']

Activity

  1. hvenev commented on Jan 6, 2016

    hvenevmannequin
    MannequinAuthor

    Should be 1. This comes from the (a%b=a if a<b) optimization.

    Let's be consistent with all other arithmetic operations.

  2. changed the title [-]True%2==True[/-] [+]True%2 is True[/+] on Jan 6, 2016
  3. SilentGhost commented on Jan 6, 2016

    SilentGhostmannequin
    Mannequin

    Arithmetic operations should not be used with booleans, they happen to work due to boolean bean a subclass of int.

  4. hvenev commented on Jan 7, 2016

    hvenevmannequin
    MannequinAuthor

    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))
  5. reopened this on Jan 7, 2016
  6. SilentGhost commented on Jan 7, 2016

    SilentGhostmannequin
    Mannequin

    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.

  7. hvenev commented on Jan 7, 2016

    hvenevmannequin
    MannequinAuthor

    One last thing: type(a%b) is A, type(b%a) is int.

  8. hvenev commented on Jan 7, 2016

    hvenevmannequin
    MannequinAuthor

    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)

  9. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions