classification
Title: assert statement violates the documentation
Type: behavior Stage: committed/rejected
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amyodov, ezio.melotti, petri.lehtinen, python-dev
Priority: normal Keywords:

Created on 2011-10-26 15:43 by amyodov, last changed 2011-10-27 12:24 by python-dev. This issue is now closed.

Messages (2)
msg146434 - (view) Author: Alexander Myodov (amyodov) Date: 2011-10-26 15:43
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.
msg146485 - (view) Author: Roundup Robot (python-dev) Date: 2011-10-27 12:24
New changeset 7bef55ae5753 by Benjamin Peterson in branch '2.7':
don't let a tuple msg be interpreted as arguments to AssertionError (closes #13268)
http://hg.python.org/cpython/rev/7bef55ae5753
History
Date User Action Args
2011-10-27 12:24:58python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg146485

resolution: fixed
stage: needs patch -> committed/rejected
2011-10-27 03:54:19ezio.melottisetnosy: + ezio.melotti

stage: needs patch
2011-10-26 17:49:56petri.lehtinensetnosy: + petri.lehtinen

components: + Interpreter Core
versions: - Python 2.6
2011-10-26 16:12:37amyodovsettitle: assert -> assert statement violates the documentation
2011-10-26 15:43:49amyodovcreate