Q:

Change class of object within __init__()

I am trying to create my own Fractions class and my own Numbers class for a project that I am working on. I was wondering how do I change the class of the fractions class to a number, if the denominator is 1.
When I looked this problem it up, I came across casting and I tried to incorporate that into my code, however the class still did not change.
class Number():
    def __init__(self,number):
        if isinstance(number,int):
            self.number = number
        elif isinstance(number, Fraction) and number.denominator == 1:
            self.number = number.numerator
        else:
            raise TypeError()

class Fraction():
    def __init__(self, numerator, denominator=Number(1)):
        self.denominator = denominator
        self.numerator = numerator
        if self.denominator == 1:
            self.__class__ == Number

print(type(Fraction(5)))
#I expected to get <class '__main__.Number'> but instead got <class '__main__.Fraction'>

A:

Using __new()__ worked when I returned the class of the Number.
I found this website very useful: click here

