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

Douglas Palma
Douglas Palma
3,471 Points

Not passing task2

watched the video a few times but still not passing. im giving my brain a little break can anyone see what im doing wrong?

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

1 Answer

nicole lumpkin
PLUS
nicole lumpkin
Courses Plus Student 5,328 Points

Hey there!

Honestly, I remember going through this unit and my brain was just fried :) So first off new is a magic method used with immutable types such as int. So it doesn't make sense to bring init into the mix, since that's used for mutable types. Your first two lines of code are perfect, now on to the weird part(at least it is for me). Because new has a return value we need to create an instance(in this case, a new integer instance) to return. I believe it is conventional to assign said instance to a variable named self, then return it.

class Double(int)
    def __new__(*args, **kwargs):
        self = int.__new__(*args, **kwargs)
        return self

Hope this helps :)