This is not possible:
from typing import Union
def make_an_object(cls: type):
"""Returns an object constructed based on information about cls"""
class Number:
def __init__(self, num: Union[float, int, Number]):
if isinstance(num, Number):
num = num.num
self.num = num
foo = make_an_object(__class__)
Of course, one could use __class__
for the isinstance
.
For the type annotations I can use "Number" (but I'd prefer to be able to use the type itself!).
And for the make_an_object
... well I don't know.
Is there a way to reference the class you're making in the class itself (recursion-style)?
Notes:
- The example above is just an example, not the problem I'm trying to solve
- One can achieve the reference problem with subclassing, but looking for a simpler solution.