How to type annotate a recursive data structure in python?

Viewed 670

I want to create a simple nested dictionary what is ultimately str-to-str mappings. As a dictionary, an example instance might look like:

{
  'l_0_0': 'string_0',
  'l_0_1': 'string_1',
  'l_0_2': {
     'l_2_0': {
        'l_3_0': 'another_string'
     }
  }
}

A less descriptive type annotation might look like Dict[str, Any], but I want to enforce something more specific than Any for my search across this tree.

def do_something(t: Dict[str, Any]):
    # Do some really cool algorithm
0 Answers
Related