-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix python linting errors #112499
Fix python linting errors #112499
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
@rustbot label -T-bootstrap -T-compiler -T-libs -T-rustdoc |
The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo |
Changes related to rustdoc nd rustc_codegen_gcc look good to me. Could you add the lint check into CI too please? |
Thanks, I'm in talks about doing that now at #112482 🙂 |
7b5b07e
to
0c9eb91
Compare
All of these changes are trivial best practice items: |
Yeah I looked over the Miri changes. That's a classic footgun, thanks for the fix. |
I don't understand the miri script diff, could you explain? |
Python default arguments are initialized when the function definition itself is evaluated, not when the function is called. def func(key, x={}):
x[key] = "oof"
print(x)
func("first")
func("second") Prints:
Therefore, it is best practice to always use one of Python's immutable types as the initializer for a optional argument. It's pretty rare to see anything other than |
Mutable containers as default args get instantiated once per definition (not once per call), and they get the same scope as the function itself. This can just lead to some surprises: def test(skip, env={}):
if skip:
env[“MIRI_SKIP_EVERYTHING”] = “1”
print(skip, env)
test(skip=True)
test(skip=False) output:
It’s working fine here since env isn’t modified within the function, but it’s just the kind of thing that’s easy to quietly “whoops” at some point edit: I see you beat me to it while I was still editing @saethlin 🙂 |
Oh wow wtf, I had no idea.^^ Good catch (and a massive footgun in Python, who would ever want mutable default arguments...).
|
@bors r+ |
…mpiler-errors Rollup of 8 pull requests Successful merges: - rust-lang#112232 (Better error for non const `PartialEq` call generated by `match`) - rust-lang#112499 (Fix python linting errors) - rust-lang#112596 (Suggest correct signature on missing fn returning RPITIT/AFIT) - rust-lang#112606 (Alter `Display` for `Ipv6Addr` for IPv4-compatible addresses) - rust-lang#112781 (Don't consider TAIT normalizable to hidden ty if it would result in impossible item bounds) - rust-lang#112787 (Add gha problem matcher) - rust-lang#112799 (Clean up "doc(hidden)" check) - rust-lang#112803 (Format the examples directory of cg_clif) r? `@ghost` `@rustbot` modify labels: rollup
…ulacrum Fix python linting errors These were flagged by `ruff`, run using the config in rust-lang#112482
These were flagged by
ruff
, run using the config in #112482