You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are several for loops in the dataclasses module where performance would presumably improve with list comprehensions. Arguably the code becomes a bit clearer as well.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
keithasaurus
changed the title
Convert several for loops in data classes to list comprehensions
Convert several for loops in dataclasses module to list comprehensions
Jan 13, 2024
It's rarely advisable to presume that something will improve performance without benchmarking it :) In all Python versions prior to 3.12, it's likely that if anything this conversion would have been a performance regression. In 3.12+ I expect it shouldn't be a regression anymore, due to comprehension inlining, but I doubt it will be a meaningful improvement, either. Without benchmarks, we should not consider performance as a factor.
I do personally find the code a bit nicer with the comprehensions, but we don't usually take PRs for such minor and subjective code changes, just due to the inherent risk of any change.
Yesterday I, as main idlelib maintainer, replaced 6 awkward lines in an IDLE test method, including a nested function, with a much clearer one-line dict comprehension. If I were the main dataclass maintainer, I would likely merge the two return changes, maybe with a format tweak, as they improve the parallelism of the if-else returns. But think the current dataclass module experts, @ericvsmith and @carljm should decide this one. I might check whether the affected functions are covered by tests.
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
There are several for loops in the dataclasses module where performance would presumably improve with list comprehensions. Arguably the code becomes a bit clearer as well.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
The text was updated successfully, but these errors were encountered: