fizzbuzz icon indicating copy to clipboard operation
fizzbuzz copied to clipboard

Type Annotation Improvement

Open vlad-bezden opened this issue 3 years ago • 0 comments

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

vlad-bezden avatar Aug 24 '20 11:08 vlad-bezden