mirror of
https://github.com/beetbox/beets.git
synced 2026-01-11 02:13:28 +01:00
Replace Py3.10+ pattern matching with isinstance
This commit is contained in:
parent
913d51af5c
commit
9bc586d7ea
1 changed files with 21 additions and 23 deletions
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue