0

I mean when we have something like

def returnNumber() -> int | None:
   return 1

Is there any way to specify in the init function that we are going to return the class itself?

class Tree:
  def __init__(self) -> Tree: #hereeee  

because in language server auto completion appears

() -> None #this with a class init
() -> int|None # this with the function example
  • 6
    `__init__()` doesn't return a class or an object, it always returns `None` and cannot be changed. – Ahmed AEK Oct 09 '22 at 19:52
  • 3
    when you instantiate an instance, python first calls `__new__()` which returns the instance, then calls the object's `__init__()` to initialize it, and `__init__()` itself has to return `None` as it is not responsible for creating the object. – Ahmed AEK Oct 09 '22 at 19:58

0 Answers0