2

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
tarabyte
  • 17,837
  • 15
  • 76
  • 117
  • `mypy`, at least, does not support recursive types at the moment, which is what you are looking for (something like `D = Dict[str,Union[str,'D']]`). – chepner Jun 26 '20 at 14:01

0 Answers0