Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Scripts/deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ def process_content(lines: Iterable[str]) -> tuple[list[str], list[str], Stats]:

# Flatten rules and their comments
rules = []
extend = rules.extend
append = rules.append
for rule, comments in rules_with_comments:
rules.extend(comments)
rules.append(rule)
if comments:
extend(comments)
append(rule)
Comment on lines +86 to +91
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Python 3.11+ (and specifically Python 3.13+ as targeted by this repository), manual caching of bound methods like extend = rules.extend and append = rules.append is an obsolete micro-optimization. The specializing adaptive interpreter (PEP 659) automatically optimizes these attribute lookups at the bytecode level after a few iterations.

Removing these manual local variable assignments improves readability and maintainability while keeping the beneficial if comments: check to avoid empty list extensions.

    for rule, comments in rules_with_comments:
        if comments:
            rules.extend(comments)
        rules.append(rule)
References
  1. The repository specifies Python 3.13+ as the target version, where PEP 659 specializing adaptive interpreter optimizations are fully active, making manual method caching obsolete. (link)


stats.headers = len(headers)
stats.final = len(headers) + len(rules)
Expand Down
Loading