Uh oh!
There was an error while loading. Please reload this page.
Fix python linting errors - #112499
Conversation
rustbot
commented
Jun 10, 2023
(rustbot has picked a reviewer for you, use r? to override) |
tgross35
commented
Jun 10, 2023
@rustbot label -T-bootstrap -T-compiler -T-libs -T-rustdoc |
rustbot
commented
Jun 10, 2023
The Miri subtree was changed cc @rust-lang/miri Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo |
GuillaumeGomez
commented
Jun 10, 2023
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 🙂 |
Uh oh!
There was an error while loading. Please reload this page.
7b5b07e to
0c9eb91Comparetgross35
commented
Jun 11, 2023
All of these changes are trivial best practice items: |
saethlin
commented
Jun 11, 2023
Yeah I looked over the Miri changes. That's a classic footgun, thanks for the fix. |
RalfJung
commented
Jun 11, 2023
I don't understand the miri script diff, could you explain? |
saethlin
commented
Jun 11, 2023
Python default arguments are initialized when the function definition itself is evaluated, not when the function is called. deffunc(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: deftest(skip, env={}):
ifskip:
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 🙂 |
RalfJung
commented
Jun 12, 2023
via email
Oh wow wtf, I had no idea.^^ Good catch (and a massive footgun in Python, who would ever want mutable default arguments...). |
Uh oh!
There was an error while loading. Please reload this page.
Mark-Simulacrum
commented
Jun 19, 2023
@bors r+ |
bors
commented
Jun 19, 2023
…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