I'm trying to use a match block to evaluate the types being returned from typing.get_type_hints. I want to use the type hinting to determine what code path to take in order to instantiate the appropriate value.
class Foo:
x: int = 0
y: float = 0.0
z: str = ''
name = 'x' # comes from an external source
value = '42'
type_hints = get_type_hints(Foo)
foo = Foo()
match type_hints[name]:
case int:
foo[name] = int(value)
case float:
foo[name] = int(value)
case str:
foo[name] = value
# TODO: other complex type parsing (e.g., Enums)
This is the error I'm getting:
C:\dev\bdk-git\bdk\venv\Scripts\python.exe C:/dev/bdk-git/bdk/material/reader.py
File "C:\dev\bdk-git\bdk\material\reader.py", line 22
case int:
^^^
SyntaxError: name capture 'int' makes remaining patterns unreachable
What is the correct syntax to accomplish what I want to do?