From e5e20a53b2348fb942b8c19ace28f33db4fc60be Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 8 Aug 2021 12:49:41 +0300 Subject: [PATCH] Makes `type.__prepare__` a classmethod, also first arg is any (not str), refs #2762 --- extra_tests/snippets/builtin_type.py | 3 +++ vm/src/builtins/pytype.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/extra_tests/snippets/builtin_type.py b/extra_tests/snippets/builtin_type.py index 4245b54cc..d97b6b29d 100644 --- a/extra_tests/snippets/builtin_type.py +++ b/extra_tests/snippets/builtin_type.py @@ -135,5 +135,8 @@ assert type.__prepare__('name', (bytes, str)) == {} assert type.__prepare__(a=1, b=2) == {} assert type.__prepare__('name', (object, int), kw=True) == {} +# Previously we needed `name` to be `str`: +assert type.__prepare__(1) == {} + assert int.__prepare__() == {} assert int.__prepare__('name', (object, int), kw=True) == {} diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 8e22da8ff..bb526d9e5 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -343,9 +343,10 @@ impl PyType { .insert("__module__".to_owned(), value); } - #[pymethod(magic)] + #[pyclassmethod(magic)] fn prepare( - _name: OptionalArg, + _cls: PyTypeRef, + _name: OptionalArg, _bases: OptionalArg, _kwargs: KwArgs, vm: &VirtualMachine,