Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MNT: Enforce ruff/Perflint rules (PERF)#28970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
DimitriPapadopoulos wants to merge5 commits intonumpy:main
base:main
Choose a base branch
Loading
fromDimitriPapadopoulos:PERF

Conversation

DimitriPapadopoulos
Copy link
Contributor

Left out because I seem to recall maintainers don't like it:

@charris
Copy link
Member

Needs rebase.

@DimitriPapadopoulos
Copy link
ContributorAuthor

Rebased.

for kinrange(len(desired)):
assert_equal(actual[k],desired[k], f'item={k!r}\n{err_msg}',
for k, iinenumerate(desired):
assert_equal(actual[k],i, f'item={k!r}\n{err_msg}',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is less readable than before, but maybe we have to accept these changes to have the benefits of ruff. Renaming thei would help here though. Another option would be to turn of the performance rules for the tests (as test performance is typically not critical)

Copy link
Member

Choose a reason for hiding this comment

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

It's very much out-of-scope here, but generally speaking it's preferable to use parametric tests instead of putting assertions in a for-loop 🤷🏻

But even so, I agree that it wouldn't hurt to renamei to something more descriptive.

Copy link
ContributorAuthor

@DimitriPapadopoulosDimitriPapadopoulosMay 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

To tell the truth, therange(len())enumerate() change hasnot been suggested byruff. I added it for consistency with thedesired.keys()desired.items() change a few lines before.

I am happy to revert therange(len))enumerate() change and disable thedesired.keys()desired.items(), globally or locally.

Note that PERF rules are not necessarily about "performance" as such. In most cases, these micro-optimisations will have only (very) marginal effect on actual global performance. Rather, the idea of all these rules is to use consistent Python style.

@@ -124,7 +124,7 @@ def assert_equal(actual, desired, err_msg=''):
for k, i in desired.items():
if k not in actual:
raise AssertionError(f"{k} not in {actual}")
assert_equal(actual[k],desired[k], f'key={k!r}\n{err_msg}')
assert_equal(actual[k],i, f'key={k!r}\n{err_msg}')
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is not the one suggested by the latest version of ruff (on my system at least). Instead of the change here we could also write this as

for k in desired.keys():            if k not in actual:                raise AssertionError(f"{k} not in {actual}")            assert_equal(actual[k], desired[k], f'key={k!r}\n{err_msg}')

Copy link
ContributorAuthor

@DimitriPapadopoulosDimitriPapadopoulosMay 15, 2025
edited
Loading

Choose a reason for hiding this comment

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

I seem to recall no fixes were available here, or perhaps only "unsafe fixes". But yes, I went for a different fix to address the "performance" issue, perhaps at the expense of readability. I will follow your advice and use the above change instead.

DimitriPapadopoulosand others added4 commitsMay 16, 2025 08:35
PERF102 When using only the values of a dict use the `values()` methodPERF102 When using only the keys of a dict use the `keys()` method
PERF403 Use `dict.update` instead of a for-loopPERF403 Use a dictionary comprehension instead of a for-loop
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
@eendebakpt
Copy link
Contributor

The changes itself look fine now. On enabling thePERF rule I am +0.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@eendebakpteendebakpteendebakpt left review comments

@jorenhamjorenhamjorenham left review comments

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@DimitriPapadopoulos@charris@eendebakpt@jorenham

[8]ページ先頭

©2009-2025 Movatter.jp