Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Double

Andy McDonald
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Andy McDonald
Python Development Techdegree Graduate 13,801 Points

I have no idea whats going on -- overridding __new__

Kenneth is talking about ovverridding magic methods and i dont really know what this whole video is talking about. The quiz is asking me to override new. I dont even know what to ask...

doubler.py
class Double(int):
    def __new__(**args, **kwargs):
        super().__new__(**args, **kwargs)
        return __new__(**args, **kwargs)

1 Answer

Hey Andy McDonald !

You are fairly close with the code you currently have. There are just a few things to change.

class Double(int):
    def __new__(**args, **kwargs):
        super().__new__(**args, **kwargs)            # this line can be removed
        return __new__(**args, **kwargs)

First, *args should only have 1 asterisk in front of them. Otherwise the python interpreter is reading it as if it has keywords. Second, we only want to return a created instance of int that sets the value of __new__ to the passed in *args and **kwargs. To create an instance, you can put int. in front of __new__(*args, **kwargs) when you return it.

I hope this helps. Don't hesitate to reach back out if you are still stuck :)