Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions crates/vm/src/builtins/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,7 @@ impl Constructor for PyFunction {
let mut func = Self::new(args.code.clone(), args.globals.clone(), vm)?;
// Set function name if provided
if let Some(name) = args.name.into_option() {
*func.name.lock() = name.clone();
// Also update qualname to match the name
*func.qualname.lock() = name;
*func.name.lock() = name;
}
// Now set additional attributes directly
if let Some(closure_tuple) = closure {
Expand Down
15 changes: 15 additions & 0 deletions extra_tests/snippets/stdlib_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,18 @@ def _run_missing_type_params_regression():
deep_alias = list[deep_alias]
with assert_raises(RecursionError):
hash(deep_alias)


# FunctionType preserves the code qualified name when a name is supplied.
def outer():
def nested():
pass

return nested


original = outer()
for name in ("renamed", ""):
function = types.FunctionType(original.__code__, globals(), name)
assert function.__name__ == name

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remove the prohibited test assertion additions

This added regression changes test logic and introduces new assertions in an extra_tests/snippets test, but the repository rules prohibit modifying test assertions or logic and limit test-file edits to adding or removing expectedFailure markers. Remove the snippet changes from this patch so the runtime fix complies with the contribution policy.

AGENTS.md reference: AGENTS.md:L275-L279

Useful? React with 👍 / 👎.

assert function.__qualname__ == "outer.<locals>.nested"
Loading