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

Performance: ruff rules C4 and PERF #5855

Merged
merged 2 commits into from
Aug 25, 2023
Merged

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Aug 22, 2023

Thank you for contributing to Pipenv!

Use ruff rules C4 and PERF to improve runtime performance

% ruff --select=C4,PERF .

pipenv/cli/options.py:175:17: PERF402 Use `list` or `list.copy` to create a copy of a list
pipenv/cli/options.py:239:17: PERF402 Use `list` or `list.copy` to create a copy of a list
pipenv/environment.py:351:17: PERF401 Use a list comprehension to create a transformed list
pipenv/environment.py:356:17: PERF401 Use a list comprehension to create a transformed list
pipenv/environment.py:813:28: C408 [*] Unnecessary `dict` call (rewrite as a literal)
pipenv/project.py:1093:20: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
pipenv/project.py:1096:32: C403 [*] Unnecessary `list` comprehension (rewrite as a `set` comprehension)
pipenv/routines/graph.py:101:25: PERF401 Use a list comprehension to create a transformed list
pipenv/routines/install.py:155:20: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/routines/install.py:553:13: PERF203 `try`-`except` within a loop incurs performance overhead
pipenv/routines/lock.py:104:16: C414 [*] Unnecessary `list` call within `set()`
pipenv/routines/lock.py:105:17: C414 [*] Unnecessary `list` call within `set()`
pipenv/routines/outdated.py:45:13: PERF203 `try`-`except` within a loop incurs performance overhead
pipenv/routines/uninstall.py:89:35: C414 [*] Unnecessary `list` call within `set()`
pipenv/routines/update.py:126:20: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/routines/update.py:187:32: PERF102 [*] When using only the keys of a dict use the `keys()` method
pipenv/utils/dependencies.py:1056:24: C419 [*] Unnecessary list comprehension.
pipenv/utils/dependencies.py:1099:42: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/fileutils.py:204:12: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/fileutils.py:208:20: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/funktools.py:301:13: PERF203 `try`-`except` within a loop incurs performance overhead
pipenv/utils/internet.py:145:21: PERF401 Use a list comprehension to create a transformed list
pipenv/utils/locking.py:262:16: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/markers.py:65:23: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/markers.py:167:17: PERF401 Use a list comprehension to create a transformed list
pipenv/utils/markers.py:624:9: PERF401 Use a list comprehension to create a transformed list
pipenv/utils/markers.py:659:9: PERF401 Use a list comprehension to create a transformed list
pipenv/utils/pip.py:143:9: PERF402 Use `list` or `list.copy` to create a copy of a list
pipenv/utils/pipfile.py:304:16: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/requirementslib.py:374:13: PERF203 `try`-`except` within a loop incurs performance overhead
pipenv/utils/resolver.py:382:13: PERF402 Use `list` or `list.copy` to create a copy of a list
pipenv/utils/shell.py:313:12: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/shell.py:317:20: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
pipenv/utils/toml.py:25:13: PERF401 Use a list comprehension to create a transformed list
pipenv/utils/virtualenv.py:428:24: C408 [*] Unnecessary `dict` call (rewrite as a literal)
tasks/vendoring/__init__.py:268:22: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
tasks/vendoring/__init__.py:723:18: C413 [*] Unnecessary `list` call around `sorted()`
tests/integration/conftest.py:41:9: PERF203 `try`-`except` within a loop incurs performance overhead
tests/integration/test_install_twists.py:190:15: C416 [*] Unnecessary `list` comprehension (rewrite using `list()`)
tests/integration/test_lock.py:631:41: C408 [*] Unnecessary `dict` call (rewrite as a literal)
tests/unit/test_utils.py:128:24: C408 [*] Unnecessary `dict` call (rewrite as a literal)
Found 41 errors.
[*] 24 potentially fixable with the --fix option.

% ruff --select=C4,PERF --fix .

Found 41 errors (24 fixed, 17 remaining).

... Manual fixes.

The issue

What is the thing you want to fix? Is it associated with an issue on GitHub? Please mention it.

Always consider opening an issue first to describe your problem, so we can discuss what is the best way to amend it. Note that if you do not describe the goal of this change or link to a related issue, the maintainers may close the PR without further review.

If your pull request makes a non-insignificant change to Pipenv, such as the user interface or intended functionality, please file a PEEP.

https://github.com/pypa/pipenv/blob/master/peeps/PEEP-000.md

The fix

How does this pull request fix your problem? Did you consider any alternatives? Why is this the best solution, in your opinion?

The checklist

  • Associated issue
  • A news fragment in the news/ directory to describe this fix with the extension .bugfix.rst, .feature.rst, .behavior.rst, .doc.rst. .vendor.rst. or .trivial.rst (this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.

@oz123
Copy link
Contributor

oz123 commented Aug 23, 2023

@cclauss thanks. Looks really interesting. I'm going to wait for the current shake down of the latest refactoring that @matteius did to relax. Then we can definitely merge this request and attend the recommendations.

@oz123 oz123 merged commit 2062c6b into pypa:main Aug 25, 2023
@cclauss cclauss deleted the ruff-rules-C4-and-PERF branch August 25, 2023 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants