Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert statement violates the documentation #57477

Closed
amyodov mannequin opened this issue Oct 26, 2011 · 2 comments
Closed

assert statement violates the documentation #57477

amyodov mannequin opened this issue Oct 26, 2011 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@amyodov
Copy link
Mannequin

amyodov mannequin commented Oct 26, 2011

BPO 13268
Nosy @ezio-melotti, @akheron

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 2011-10-27.12:24:58.922>
created_at = <Date 2011-10-26.15:43:49.248>
labels = ['interpreter-core', 'type-bug']
title = 'assert statement violates the documentation'
updated_at = <Date 2011-10-27.12:24:58.911>
user = 'https://bugs.python.org/amyodov'

bugs.python.org fields:

activity = <Date 2011-10-27.12:24:58.911>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2011-10-27.12:24:58.922>
closer = 'python-dev'
components = ['Interpreter Core']
creation = <Date 2011-10-26.15:43:49.248>
creator = 'amyodov'
dependencies = []
files = []
hgrepos = []
issue_num = 13268
keywords = []
message_count = 2.0
messages = ['146434', '146485']
nosy_count = 4.0
nosy_names = ['ezio.melotti', 'amyodov', 'python-dev', 'petri.lehtinen']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue13268'
versions = ['Python 2.7']

@amyodov
Copy link
Mannequin Author

amyodov mannequin commented Oct 26, 2011

The extended version of assert statement has a strange violation of documented behaviour.

According to the http://docs.python.org/reference/simple_stmts.html#the-assert-statement, "assert expression1, expression2" should be equivalent to "if __debug__: if not expression1: raise AssertionError(expression2)". Nevertheless, it is not so for the following scenario:

class A(object):
    def __str__(self):
        return "str"
    def __unicode__(self):
        return "unicode"
    def __repr__(self):
        return "repr"

expression1 = False
expression2 = (A(),)

That is, when expression2 is a single-item tuple, assert statement prints the str-evaluation of the item itself, rather than of the tuple.

This occurs in 2.x branch only, seems fixed in 3.x, and it would be great to have it backported for consistency.

@amyodov amyodov mannequin added the type-bug An unexpected behavior, bug, or error label Oct 26, 2011
@amyodov amyodov mannequin changed the title assert assert statement violates the documentation Oct 26, 2011
@akheron akheron added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Oct 26, 2011
@python-dev
Copy link
Mannequin

python-dev mannequin commented Oct 27, 2011

New changeset 7bef55ae5753 by Benjamin Peterson in branch '2.7':
don't let a tuple msg be interpreted as arguments to AssertionError (closes bpo-13268)
http://hg.python.org/cpython/rev/7bef55ae5753

@python-dev python-dev mannequin closed this as completed Oct 27, 2011
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant