msg 176928 created
issue 16608 created
clear this message

classification
Title: immutable subclass constructor call error does not show subclass name
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.4, Python 3.3, Python 3.2, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: LambertDW, r.david.murray
Priority: low Keywords:

Created on 2012-12-04 18:54 by LambertDW, last changed 2012-12-04 20:23 by r.david.murray.

Messages (6)
msg176928 - (view) Author: David W. Lambert (LambertDW) Date: 2012-12-04 18:54
http://forums.devshed.com/newreply.php?do=newreply&noquote=1&p=2838814

>>> class c(tuple):
...  def __init__(s,a,b):
...   tuple.__init__(s,a)
...   self.b = b
...
>>> c(tuple(),666)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: tuple() takes at most 1 argument (2 given)
>>>
msg176937 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-12-04 19:33
Is your error report the fact that the name 'tuple' appears in the error message instead of 'c'?  That does seem sub-optimal.  It may not be easy to improve, though.
msg176938 - (view) Author: David W. Lambert (LambertDW) Date: 2012-12-04 19:42
The apparent problem was that the constructing str with __init__ failed.  I now recall that immutables take initial values in the __new__ method.  Sorry!  Otherwise, it was quite thoughtful for you to search for a problem.  Dave.
msg176946 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-12-04 20:08
I have no idea what you are referring to by 'constructing str' :(

I thought at first it was your incorrect tuple call in the init that was the issue, but that didn't look right, and after reproducing it and playing with it for a bit I figured out it was the __new__ failure, and I realized the reason I was confused was that the error message said 'tuple' instead of 'c'.  So I definitely think that message could use improvement if it is practical.
msg176948 - (view) Author: David W. Lambert (LambertDW) Date: 2012-12-04 20:20
Sorry again.  You probably didn't follow the link I posted to see the
problem origination.   Which was "Cannot subclass str."  I generalized
this to tuple.

On Tue, 2012-12-04 at 20:08 +0000, R. David Murray wrote:
> R. David Murray added the comment:
> 
> I have no idea what you are referring to by 'constructing str' :(
> 
> I thought at first it was your incorrect tuple call in the init that was the issue, but that didn't look right, and after reproducing it and playing with it for a bit I figured out it was the __new__ failure, and I realized the reason I was confused was that the error message said 'tuple' instead of 'c'.  So I definitely think that message could use improvement if it is practical.
> 
> ----------
> 
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16608>
> _______________________________________
msg176950 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-12-04 20:23
I followed the link, but it took me to a login/signup form, so it wasn't very informative.
History
Date User Action Args
2012-12-04 20:23:46r.david.murraysetmessages: + msg176950
2012-12-04 20:20:44LambertDWsetmessages: + msg176948
2012-12-04 20:08:40r.david.murraysetmessages: + msg176946
2012-12-04 19:42:27LambertDWsetmessages: + msg176938
2012-12-04 19:33:37r.david.murraysetpriority: normal -> low
title: subclass str fails -> immutable subclass constructor call error does not show subclass name
nosy: + r.david.murray

messages: + msg176937

versions: + Python 3.3, Python 3.4
2012-12-04 18:54:03LambertDWcreate