Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve ruff literal-membership #9572

Merged
merged 1 commit into from
Dec 18, 2024
Merged

Conversation

berland
Copy link
Contributor

@berland berland commented Dec 17, 2024

ruff check --fix --unsafe-fixes

literal-membership (PLR6201)

Derived from the Pylint linter.

Fix is always available.

This rule is in preview and is not stable. The --preview flag is required for use.

What it does

Checks for membership tests on list and tuple literals.

Why is this bad?

When testing for membership in a static sequence, prefer a set literal
over a list or tuple, as Python optimizes set membership tests.

Example

1 in [1, 2, 3]

Use instead:

1 in {1, 2, 3}

Fix safety

This rule's fix is marked as unsafe, as the use of a set literal will
error at runtime if the sequence contains unhashable elements (like lists
or dictionaries). While Ruff will attempt to infer the hashability of the
elements, it may not always be able to do so.

References

  • What’s New In Python 3.2

  • PR title captures the intent of the changes, and is fitting for release notes.

  • Added appropriate release note label

  • Commit history is consistent and clean, in line with the contribution guidelines.

  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'pytest tests/ert/unit_tests -n logical -m "not integration_test"')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Create Backport PR to latest release

ruff check --fix --unsafe-fixes
@berland berland self-assigned this Dec 17, 2024
@berland berland added the release-notes:maintenance Automatically categorise as maintenance change in release notes label Dec 17, 2024
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.86%. Comparing base (0e19012) to head (20b60b3).

Files with missing lines Patch % Lines
src/ert/gui/simulation/run_dialog.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9572      +/-   ##
==========================================
- Coverage   91.87%   91.86%   -0.01%     
==========================================
  Files         433      433              
  Lines       26770    26770              
==========================================
- Hits        24595    24593       -2     
- Misses       2175     2177       +2     
Flag Coverage Δ
cli-tests 39.76% <56.25%> (ø)
everest-models-test 34.66% <24.32%> (ø)
gui-tests 72.11% <59.37%> (-0.03%) ⬇️
integration-test 37.22% <21.62%> (+0.01%) ⬆️
performance-tests 51.94% <53.12%> (ø)
test 40.44% <24.32%> (ø)
unit-tests 74.16% <75.67%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

codspeed-hq bot commented Dec 17, 2024

CodSpeed Performance Report

Merging #9572 will not alter performance

Comparing berland:literal-membership (20b60b3) with main (0e19012)

Summary

✅ 22 untouched benchmarks

@berland berland enabled auto-merge (rebase) December 17, 2024 13:36
Copy link
Contributor

@eivindjahren eivindjahren left a comment

Choose a reason for hiding this comment

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

📝

@berland berland merged commit 6ce4714 into equinor:main Dec 18, 2024
41 checks passed
@berland berland deleted the literal-membership branch December 27, 2024 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:maintenance Automatically categorise as maintenance change in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants