From 16507ff4a3ca85f656d7abbefab39d12ea90f43d Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Tue, 30 May 2023 10:10:02 +0200 Subject: [PATCH] Simplify _relation_attributes() (#2215) Use try/except as the key should be always there, and that's the fastest in such case. Except is there to prevent any issue if the API does something weird. --- picard/mbjson.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/picard/mbjson.py b/picard/mbjson.py index ad18875ac..ff1a032ae 100644 --- a/picard/mbjson.py +++ b/picard/mbjson.py @@ -139,9 +139,10 @@ def _parse_attributes(attrs, reltype, attr_credits): def _relation_attributes(relation): - if 'attributes' in relation: - return tuple(a for a in relation['attributes']) - return tuple() + try: + return tuple(relation['attributes']) + except KeyError: + return tuple() def _relations_to_metadata_target_type_artist(relation, m, context):