[New-bugs-announce] [issue34362] User-created types with wrong __new__ can be instantiated

ppperry report at bugs.python.org
Wed Aug 8 15:07:33 EDT 2018

New submission from ppperry <mapreader at olum.org>:

If you have a class that defines __new__ to the __new__ of another builtin type that it isn't a subclass of:
>>> class X:
...    __new__ = tuple.__new__
Instantiating this class should produce an error because `tuple.__new__` can't handle non-tuples, but instead it succeeds:
>>> X()
<__main__.X object at 0x00000000032C3F98>

(related: issue34284)

components: Interpreter Core
messages: 323297
nosy: Vadim Pushtaev, ncoghlan, ppperry, serhiy.storchaka
priority: normal
severity: normal
status: open
title: User-created types with wrong __new__ can be instantiated
type: behavior
versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list