fizzbuzz
fizzbuzz copied to clipboard
Type Annotation Improvement
On page 70 there is:
from typing import Dict, NamedTuple, Optional
class Node(NamedTuple):
count: int
cla55: Optional[int] = None # None if it's a merged node
children: Dict[str, 'Node'] = {} # {} if it's a leaf node
Instead of using 'Node' use:
from __future__ import annotations # notice that it must be the first line of the module
and then you can reference the same class as Type instead of string name
children: Dict[str, Node] = {} # {} if it's a leaf node