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

Apply ruff/bugbear rules (B) #243

Closed
wants to merge 1 commit into from

Conversation

DimitriPapadopoulos
Copy link
Contributor

@DimitriPapadopoulos DimitriPapadopoulos commented Mar 10, 2024

Start addressing #240.

B006 Do not use mutable data structures for argument defaults

https://docs.astral.sh/ruff/rules/mutable-argument-default/

Don't apply this rule:

B904 Within an `except` clause, raise exceptions with `raise ... from err` or `raise ... from None` to distinguish them from errors in exception handling

https://docs.astral.sh/ruff/rules/raise-without-from-inside-except/

B006 Do not use mutable data structures for argument defaults

https://docs.astral.sh/ruff/rules/mutable-argument-default/
@DimitriPapadopoulos DimitriPapadopoulos changed the title Fix ruff/bugbear issues (B) Apply ruff/bugbear rules (B) Apr 13, 2024
@jaraco
Copy link
Member

jaraco commented Apr 14, 2024

Thanks for this request. I'd not seen it before I addressed it in 448a2a1. It's okay to pass mutable arguments as long as there's a type declaration protecting against mutating it (which there is now), so the B006 checks no longer fail:

 distutils main @ ruff check --select B006
All checks passed!

@jaraco jaraco closed this Apr 14, 2024
@DimitriPapadopoulos
Copy link
Contributor Author

Nevertheless, it's perhaps better to use =() instead of =[] as a default value and be consistent about it:

$ fgrep -R '=())'
distutils/tests/test_cmd.py:            cmd.make_file(infiles=1, outfile='', func='func', args=())
distutils/tests/test_cmd.py:        cmd.make_file(infiles='in', outfile='out', func='func', args=())
distutils/tests/test_dist.py:    def create_distribution(self, configfiles=()):
$ 
$ fgrep -R '= [])'
distutils/fancy_getopt.py:    def __init__(self, options: Sequence[Any] = []):
distutils/tests/__init__.py:def missing_compiler_executable(cmd_names: Sequence[str] = []):  # pragma: no cover
$ 

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