This works:
from typing import Union, Callable
class Ordinal:
def __init__(self, children : Union[None, 'Ordinal']):
self.children = children
This doesn't:
from typing import Union, Callable
class Ordinal:
def __init__(self, children : None | 'Ordinal'):
self.children = children
# TypeError: unsupported operand type(s) for |: 'NoneType' and 'str'
I'm fine using the first one, but would like to know what's going on here, so I make sure the first one isn't actually just implementing something entirely different.
(for clarity, I'm defining the type Ordinal
recursively with stringized annotations.)