From 9bc586d7ea94c6b8baceba1d1da4887991328eef Mon Sep 17 00:00:00 2001 From: Nicholas Boyd Isacsson Date: Sat, 5 Oct 2024 15:31:42 +0200 Subject: [PATCH] Replace Py3.10+ pattern matching with isinstance --- beetsplug/substitute.py | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/beetsplug/substitute.py b/beetsplug/substitute.py index be305ab02..84eca9de1 100644 --- a/beetsplug/substitute.py +++ b/beetsplug/substitute.py @@ -48,34 +48,32 @@ class Substitute(BeetsPlugin): Get the configuration, register template function and create list of substitute rules. """ - super().__init__() + super(Substitute, self).__init__() self.substitute_rules = [] self.template_funcs["substitute"] = self.tmpl_substitute - match self.config.get(): - case list(): - pairs = self.config.as_pairs() - case dict(): - pairs = [ - (key, view.as_str()) for key, view in self.config.items() - ] - self._log.warning( - "Unordered configuration is deprecated, as it leads to" - + " unpredictable behaviour on overlapping rules.\n" - + textwrap.dedent( - """ - Old syntax: - substitute: - a: b - c: d + if isinstance(self.config.get(), dict): + self._log.warning( + "Unordered configuration is deprecated, as it leads to" + + " unpredictable behaviour on overlapping rules.\n" + + textwrap.dedent( + """ + Old syntax: + substitute: + a: b + c: d - New syntax: - substitute: - - a: b - - c: d - """ - ) + New syntax: + substitute: + - a: b + - c: d + """ ) + ) + pairs = [(key, view.as_str()) for key, view in self.config.items()] + else: + pairs = self.config.as_pairs() + for key, value in pairs: pattern = re.compile(key, flags=re.IGNORECASE) self.substitute_rules.append((pattern, value))