'How to use match case to check for variable type in python?
I have this code to check for whether or not a variable is a number or a Vector2 in my Vector2 class when multiplying.
def __mul__(self, other):
match type(other):
case int | float:
pass
case Vector2:
pass
If I run this, I get SyntaxError: name capture 'int' makes remaining patterns unreachable, and when I hover in vscode, it gives me:
"int" is not accessed
Irrefutable pattern allowed only as the last subpattern in an "or" pattern
All subpatterns within an "or" pattern must target the same names
Missing names: "float"
Irrefutable pattern is allowed only for the last case statement
If I remove | float it still won't work, so I can't make them separate cases.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
