New submission from João Sebastião de Oliveira Bueno:

There is an specific Python behavior on object instantiation that is "expected" 
but not explicit, even for avanced users:

When a custom class defines `__init__` with extra parameters, but do not 
overrides `__new__`, it simply works. But if `__new__`is defined it has to 
match `__init__`s signature.

This behavior is not documented anywhere.

I could found this issue was discussed in this thread earlier this year, 
starting with this e-mail:
https://mail.python.org/pipermail/python-list/2016-March/704013.html

I propose the following paragraph from a follow up e-mail by "eryksun at 
gmail.com" to be added to the description of "__new__" in the Data Model 
documentation page:

"""

[The implementation] knows whether a type overrides the __new__ or
__init__ methods. You're expected to consume additional arguments in
this case. However, excess arguments are ignored in object.__new__ if
a type overrides __init__ without overriding __new__ (i.e. your second
example). Excess arguments are also ignored in object.__init__ if a
type overrides __new__ without overriding __init__.
"""
(Source: https://mail.python.org/pipermail/python-list/2016-March/704024.html)

----------
assignee: docs@python
components: Documentation
messages: 280633
nosy: João.Sebastião.de.Oliveira.Bueno, docs@python
priority: normal
severity: normal
status: open
title: Explain in the "Data Model" document why arguments to __init__ are ok 
when __new__ is not defined
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28672>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to