I am using some nested typed dictionaries and my code is working. However, I am not surprised to see warnings, when I use the Thonny Assistant, because I am not using string literals as key names everywhere in the dictionaries. However, Python does not complain at all and runs the code just fine.
But why is this sample code still working ?
from typing import TypedDict
S_Info = TypedDict('S_Info', {'Type':int, 'Avail': bool, 'Pause': bool,'Status': int})
B_Types = TypedDict('B_Types',{0x01: S_Info, 0x02: S_Info})
bmatrix: B_Types = {
0x01:{
0b000: {'Type': 0x21, 'Avail': 1, 'Pause': 0, 'Status':0},
0b001: {'Type': 0x81, 'Avail': 1, 'Pause': 0, 'Status':2},
0b010: {'Type': 0x41, 'Avail': 1, 'Pause': 0, 'Status':0}},
0x02:{
0b000: {'Type': 0x22, 'Avail': 0, 'Pause': 0, 'Status':1},
0b001: {'Type': 0x82, 'Avail': 0, 'Pause': 1, 'Status':9},
0b010: {'Type': 0x42, 'Avail': 0, 'Pause': 0, 'Status':0}}
}
print(bmatrix[0x02])
I was expecting it to fail, because I thought I needed to use string literals. However, I tried it, because I know Python sometimes is quite forgiving and it was very handy to use hex numbers, that I can create, using binary operations somewhere else in the code.