New submission from Chris Jerdonek <chris.jerdo...@gmail.com>:

When calling an instance method incorrectly, you will often get a TypeError 
that is some variation of the following:

    Traceback (most recent call last):
      File "/.../test.py", line 6, in <module>
        a.foo(1)
    TypeError: foo() takes 1 positional argument but 2 were given

However, when multiple classes have method foo() and the type of "a" isn't 
immediately obvious, this often isn't enough to know what method was being 
called. Thus, it would be more helpful if the error message includes also the 
class that foo() belongs to, or alternatively the type of the object. (These 
can be different when subclasses are involved.)

For comparison, if you call a method that doesn't exist, you will get a message 
that looks like the following:

    Traceback (most recent call last):
      File "/.../test.py", line 6, in <module>
        a.bar(1)
    AttributeError: 'A' object has no attribute 'bar'

So taking from this as an example, the message in the first case could be 
something like--

    TypeError: foo() for 'A' object takes 1 positional argument but 2 were given

----------
messages: 369324
nosy: chris.jerdonek
priority: normal
severity: normal
status: open
title: show class name in method invocation TypeError
type: enhancement
versions: Python 3.9

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

Reply via email to