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: immutable subclass constructor call error does not show subclass name
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: LambertDW, iritkatriel, r.david.murray
Priority: low Keywords:

Created on 2012-12-04 18:54 by LambertDW, last changed 2022-04-11 14:57 by admin.

Messages (7)
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.
msg387054 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-02-15 20:26
The issue still exists in 3.10:

Python 3.10.0a5+ (heads/master:bf2e7e55d7, Feb 11 2021, 23:09:25) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 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 expected at most 1 argument, got 2
>>>
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 60812
2021-02-15 20:26:55iritkatrielsetnosy: + iritkatriel

messages: + msg387054
versions: + Python 3.10, - Python 2.7, Python 3.2, Python 3.3, Python 3.4
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