◐ Shell
clean mode source ↗

Clippy warn on unnecessary wraps by ShaharNaveh · Pull Request #7869 · RustPython/RustPython

📝 Walkthrough

Walkthrough

This PR adds the Clippy lint unnecessary_wraps = "warn" to the workspace and systematically removes PyResult wrapping from hundreds of helper functions, internal methods, and stdlib functions across codegen, VM builtins, and stdlib modules. Functions now return direct values (bool, usize, String, PyObjectRef, etc.) instead of Result-wrapped equivalents, simplifying call sites by eliminating ? operators and Ok(...) wrappers where applicable. Several module-level module_exec functions and similar required-signature spots gain #[expect] annotations.

Changes

Infallibility refactor across codegen, VM, and stdlib

Layer / File(s) Summary
Clippy lint and codegen
Cargo.toml, crates/codegen/src/compile.rs
Enable unnecessary_wraps lint; refactor codegen helper signatures (varname, get_*_var_index, emit_format_validation, pattern helpers) from CompileResult to infallible; update all call sites to remove ? operators.
String parsing and format specs
crates/codegen/src/string_parser.rs, crates/common/src/format.rs
Make parse_unicode_literal and format_sign_and_align infallible; update call sites accordingly.
Derive macros and utilities
crates/derive-impl/src/*
Refactor proc-macro functions to return TokenStream directly; make ItemNursery::add_item and metadata helpers infallible; remove error propagation from code-gen item factories.
Asyncio, socket, and core stdlib
crates/stdlib/src/_asyncio.rs, crates/stdlib/src/socket.rs, crates/stdlib/src/locale.rs, crates/stdlib/src/grp.rs, crates/stdlib/src/mmap.rs, crates/stdlib/src/overlapped.rs, crates/stdlib/src/pyexpat.rs, crates/stdlib/src/select.rs, crates/stdlib/src/_sqlite3.rs, crates/stdlib/src/contextvars.rs
Update Future/Task/await, socket parse_ancillary_data, locale helpers, and context var methods to return direct values; add clippy expects where needed.
SSL and cryptography
crates/stdlib/src/ssl.rs, crates/stdlib/src/ssl/cert.rs
Simplify _SSLContext, _SSLSocket, MemoryBIO methods and cert name conversion to infallible returns.
VM builtins pickle and arithmetic
crates/vm/src/builtins/{range,set,slice,str,zip,map,int,genericalias,type}.rs, crates/vm/src/builtins/{frame,function,object,asyncgenerator}.rs
Update reduce, setstate, str, round, reversed and similar protocol methods to return direct values; add clippy expects for required-signature methods.
Exception and warning systems
crates/vm/src/exceptions.rs, crates/vm/src/warn.rs
Refactor exception str and traceback handling to infallible; convert warnings module attribute lookup from PyResult to Option-based returns with fallback logic.
ctypes FFI layer
crates/vm/src/stdlib/_ctypes.rs, crates/vm/src/stdlib/_ctypes/{array,base,pointer,structure,union,function}.rs
Update LoadLibrary, check_hresult, format_error_func, CopyComPointer, struct_union_paramfunc, get_field_size, and array element reading to direct returns; refactor error handling at call boundaries.
Other stdlib and VM
crates/stdlib/src/{_operator,_functools,_imp,_io,_signal,_symtable,_thread,_typing,builtins,itertools,nt,os,pwd,sys,time,typevar,winreg}.rs, crates/vm/src/{codecs,frame,stdlib/_ast,stdlib/_codecs,stdlib/_collections}.rs, crates/vm/src/types/slot.rs, crates/vm/src/vm/mod.rs, crates/wasm/src/vm_class.rs
Simplify dozens of method and function signatures (operator.is_, override, extension_suffixes, device_encoding, DirEntry accessors, _BootstrapStderr, _getframemodulename, TypeVar/ParamSpec getset accessors, etc.) to return direct values; add clippy expects where signatures are mandated.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • youknowone
  • coolreader18

Bunny unwrapped the wrappers with care,
Set Results free into open air.
No more Ok, no trailing sigh—
Just values hopping quickly by.
Clippy nods, the fields align;
The code now dances, sleek and fine. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests