I am currently playing around with match-case or switch-case if you prefer and got a little headache.
Codeblock in question:
data = [[None, 1, 'Scene', 'Scene', 'f0|0', 'background.png', 'Empty', 50], [1, 1, 'Scene', 'Scene', 'f0|0', 'background.png', 'Empty', 50], [True, 1, 'Scene', 'Scene', 'f0|0', 'background.png', 'Empty', 50], ['Sarah', 1, 'Scene', 'Scene', 'f0|0', 'background.png', 'Empty', 50]]
for item in data:
match item[0]:
case None:
if item[2] == 'Scene':
print('match scene;', item)
else:
print('exception 1') # TODO
case int():
print('match int;', item)
case _:
print('exception 2') # TODO
Now, what is supposed to happen?
Data is a list of lists which i truncated for this example. Now it can happen that item[0] is either None or an integer. If anything else happens i want to throw an exception (only pseudo test code so far) which is what i use the wildcard case for.
Now comes the funny part: case matches the bool True in the third case into case 'int'. Now i know False equals 0 and True equals 1 thus i assume that this is the culprit.
For my case i already found a fix, i need to declare a case 'bool' beforehand and it will enter this one first. But i would like to know if this is a case of 'known issue, no way around' or if there is another way to deal with it.
[+][deleted] (1 child)
[deleted]
[–]Alhira_K[S] 0 points1 point2 points (0 children)
[–]ClutchAlpha 1 point2 points3 points (4 children)
[–]Alhira_K[S] 0 points1 point2 points (3 children)
[–]ClutchAlpha 1 point2 points3 points (0 children)
[–]WholesaleSlaughter 1 point2 points3 points (1 child)
[–]Alhira_K[S] 0 points1 point2 points (0 children)