mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Preserve FunctionType qualified names when overriding names (#9032)
Extract the independent Python 3.14-compatible constructor fix from #8954. An explicit name replaces __name__ while __qualname__ remains the code qualified name. Add a focused regression to the existing types snippet. Assisted-by: OpenAI Codex:model identifier unavailable
This commit is contained in:
1 parent
1c7c801a3b
commit
386cd86aef
2 files changed
+16
-3
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -66,3 +66,18 @@ if sys.implementation.name == "rustpython":
|
||||
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
|
||||
assert function.__qualname__ == "outer.<locals>.nested"
|
||||
Reference in new issue
Block a user