I am looking for a simple way to make my code compatible for both python 3.10 and below.
Toy-Example:
class MatchSomething
# for 3.10
def match_matcher(self, input=23)
match input:
case 23:
print("TWENTYTHREE")
# For below 3.10
def if_matcher(self, input=23)
if input == 23:
print("TWENTYTHREE")
When I import this class under a python 3.9 environment, I obviously get "SyntaxError: invalid syntax" since it does not now the match pattern.
Is there a very simple way to solve this problem like a decorator or so? I was thinking about putting both functions in a separate file and only import the respectively compatible function depending on the python version (see answer from @ErnestBidouille). However this would also not be a very nice solution since it will reduce the readability of the code (the function will have a very crucial role)
Edit: The reason why I would like to use match over if-conditions is to increase performance.