Skip to content

Commit

Permalink
Replace Py3.10+ pattern matching with isinstance
Browse files Browse the repository at this point in the history
  • Loading branch information
nichobi committed Oct 5, 2024
1 parent 913d51a commit 9bc586d
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions beetsplug/substitute.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,32 @@ def __init__(self):
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))

0 comments on commit 9bc586d

Please sign in to comment.