[Python-ideas] Showing qualified names when a function call fails

Steven D'Aprano steve at pearwood.info
Tue Oct 25 21:11:13 EDT 2016


On Tue, Oct 25, 2016 at 04:55:21PM -0500, Ryan Gonzalez wrote:
> Also, as an extension of this idea, would it be possible to improve errors
> like this:
> 
> 
> class X: pass
> X() # object() takes no parameters
> 
> 
> to show the actual type instead of just 'object'?

My wild guess is that the cause is that __new__ looks like this:

class object():
    def __new__(cls, *args):
        if args:
             raise TypeError('object() takes no parameters')


Except in C, of course.

This is probably a left-over from the days when object() took and 
ignored any parameters. If my guess is close, then maybe we can do this:

        if args:
             raise TypeError('%s() takes no parameters' % cls.__name__)


or equivalent.

-- 
Steve


More information about the Python-ideas mailing list