[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-14 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

When reporting a failure please copy and paste the exception and message and 
when non-trivial, the traceback.   In this case:  "TypeError: 'test' is an 
invalid keyword argument for complex()".  The difference between int and 
complex versus float is that the former have keyword arguments, so they check 
for invalid keyword arguments, whereas float take no keyword arguments, so it 
does not check for validity and, for subclasses, passes them on.

--
nosy: +terry.reedy
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-13 Thread Mark Dickinson


Change by Mark Dickinson :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-12 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Here's an example:

class A(complex):
def __init__(self, *args, test):
self.test = test
def __new__(cls, *args, test):
return super().__new__(cls, *args)

>>> a = A(1, test="TEST")
>>> a
(1+0j)
>>> a.test
'TEST'

>>> b = A(1, 1, test="TEST2")
>>> b
(1+1j)
>>> b.test
'TEST2'

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-12 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

This is because int, str, and complex are immutable. If I have 

class MyInt(int):
def __init__(self, stuff):
pass

then when I call MyInt("19"), the string "19" is passed to the constructor 
int.__new__ before the overridden initializer MyInt.__init__. You can only 
override that by implementing a MyInt.__new__ to override the int constructor.

This is not a bug.

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-12 Thread autospamfighter


autospamfighter  added the comment:

I tried some more classes and str is weird, but dict and set work fine. very 
weird

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42334] Subclassing int and complex with keyword arguments weird

2020-11-12 Thread autospamfighter


New submission from autospamfighter :

I was trying to make a custom complex class that looked something like this and 
it failed. I replaced complex with int and it also failed, but I tried float 
and it worked.

---fail
class A(complex):
def __init__(self, test):
super().__init__()

A(test=5)

---fail
class A(int):
def __init__(self, test):
super().__init__()

A(test=5)

---work
class A(float):
def __init__(self, test):
super().__init__()

A(test=5)

--
components: Library (Lib)
messages: 380840
nosy: autospamfighter
priority: normal
severity: normal
status: open
title: Subclassing int and complex with keyword arguments weird
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com