[issue31506] Improve the error message logic for object_new & object_init
Nick Coghlan
report at bugs.python.org
Wed Sep 20 00:05:39 EDT 2017
Nick Coghlan added the comment:
Reopening, as I was a little hasty with the merge button: the merged PR *also* changed the `__init__` error message to drop the method name, but I don't think that's what we want.
I'm also wondering if we should change the up-call case to *always* report the method name.
That is, we'd implement the following revised behaviour:
# Without any method overrides
class C:
pass
C(42) -> "TypeError: C() takes no arguments"
C.__new__(42) -> "TypeError: C() takes no arguments"
C().__init__(42) -> "TypeError: C.__init__() takes no arguments"
# These next two quirks are the price we pay for the nicer errors above
object.__new__(C, 42) -> "TypeError: C() takes no arguments"
object.__init__(C(), 42) -> "TypeError: C.__init__() takes no arguments"
# With method overrides
class D:
def __new__(cls, *args, **kwds):
super().__new__(cls, *args, **kwds)
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
D(42) -> "TypeError: object.__new__() takes no arguments"
D.__new__(42) -> "TypeError: object.__new__() takes no arguments"
D().__init__(42) -> "TypeError: object.__init__() takes no arguments"
object.__new__(C, 42) -> "TypeError: object.__new__() takes no arguments"
object.__init__(C(), 42) -> "TypeError: object.__init__() takes no arguments"
----------
resolution: fixed ->
stage: resolved -> needs patch
status: closed -> open
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31506>
_______________________________________
More information about the Python-bugs-list
mailing list