I am trying to access Foo using Bar having a property.
class Foo:
ONE = "one"
TWO = "two"
THREE = "three"
class Bar:
@property
def foo(self):
return Foo
word = "one"
match word:
case Foo.ONE: # This is working
print("GOOD")
case Bar().foo.ONE: # This is not working
print("BEST")
What I am missing?
>Solution :
You cannot use evaluations at this place. But you can do what you want with guards:
word = "one"
match word:
case str(value) if value == Bar().foo.ONE:
print("BEST")
case str(value) if value == Foo.ONE:
print("GOOD")
The str() is not mandatory, it adds some checking on the type of word.