From faca8af32d94f852c7000565b32a96a48205d770 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Wed, 16 Oct 2024 11:39:34 -0700 Subject: [PATCH] generation: DRY list(OrderedDict) idiom A named function is also more self-documenting. Thanks to Richard for the suggestion. --- tools/generation/lib/template.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/generation/lib/template.py b/tools/generation/lib/template.py index 73965814fe..2e46ad5367 100644 --- a/tools/generation/lib/template.py +++ b/tools/generation/lib/template.py @@ -49,6 +49,11 @@ def indent(text, prefix = ' ', js_value = False): return '\n'.join(indented) + +def without_duplicates(iterable): + return list(OrderedDict.fromkeys(iterable)) + + class Template: def __init__(self, filename, encoding): self.filename = filename @@ -160,7 +165,7 @@ class Template: features = [] features += case_values['meta'].get('features', []) features += self.attribs['meta'].get('features', []) - features = list(OrderedDict.fromkeys(features)) + features = without_duplicates(features) if len(features): lines += ['features: ' + yaml.dump(features, default_flow_style=True, width=float('inf')).strip()] @@ -176,7 +181,7 @@ class Template: flags = ['generated'] flags += case_values['meta'].get('flags', []) flags += self.attribs['meta'].get('flags', []) - flags = list(OrderedDict.fromkeys(flags)) + flags = without_duplicates(flags) if 'async' in flags and negative and negative.get('phase') == 'parse' and negative.get('type') == 'SyntaxError': flags.remove('async') lines += ['flags: ' + yaml.dump(flags, default_flow_style=True, @@ -185,7 +190,7 @@ class Template: includes = [] includes += case_values['meta'].get('includes', []) includes += self.attribs['meta'].get('includes', []) - includes = list(OrderedDict.fromkeys(includes)) + includes = without_duplicates(includes) if len(includes): lines += ['includes: ' + yaml.dump(includes, default_flow_style=True, width=float('inf')).strip()]