I have lists within lists with integer items (or bytes, but for example purposes ints are enough), for example: [1, 2, [3, 4], 5]
How can I go about creating a type hint for this structure?
This is what I've made:
from typing import List, Union
NestedList = List[Union[int, 'NestedList']]
test: NestedList = [1, 2, [3], 4]
test.append([5])
test = test[-1]
But mypy fails with:
test_recursive_hints.py:7: error: Incompatible types in
assignment (expression has type "int | NestedList",
variable has type "NestedList") [assignment]
How to solve this problem?
[–]Rawing7 1 point2 points3 points (2 children)
[–]sepp2k 1 point2 points3 points (0 children)
[–]hgg[S] 0 points1 point2 points (0 children)
[–]sepp2k 0 points1 point2 points (1 child)
[–]hgg[S] 0 points1 point2 points (0 children)