classification
Title: Inconsistent behaviour around __new__
Type: behavior Stage: resolved
Components: Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Assigning and deleting __new__ attr on the class does not allow to create instances of this class
View: 25731
Assigned To: Nosy List: Barney Stratford
Priority: normal Keywords:

Created on 2018-11-04 14:46 by Barney Stratford, last changed 2018-11-04 15:01 by serhiy.storchaka. This issue is now closed.

Messages (1)
msg329231 - (view) Author: Barney Stratford (Barney Stratford) * Date: 2018-11-04 14:46
>>> class Eggs (object):
...  def __init__ (self, number):
...   self.__number = number
...  def __repr__ (self):
...   return "{} eggs".format (self.__number)
... 
>>> Eggs (4)
4 eggs
>>> del Eggs.__new__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __new__
>>> # As expected
...
>>> Eggs (4)
4 eggs
>>> Eggs.__new__ = None
>>> del Eggs.__new__
>>> Eggs (4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object() takes no parameters
>>> # Wrong! Eggs has no __new__, so this should respond as earlier
...

This bug seems to be because the slotdef isn't updated when __new__ is deleted.
History
Date User Action Args
2018-11-04 15:01:01serhiy.storchakasetstatus: open -> closed
superseder: Assigning and deleting __new__ attr on the class does not allow to create instances of this class
resolution: duplicate
stage: resolved
2018-11-04 14:46:46Barney Stratfordcreate