From c0f38e22630f04e86c57fb7f56dac4697cf1fbdb Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 9 Aug 2021 16:33:57 +0300 Subject: [PATCH] Adds `__subclasshook__` to `type`, refs #2794 --- extra_tests/snippets/builtin_type.py | 7 +++++++ vm/src/builtins/pytype.rs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/extra_tests/snippets/builtin_type.py b/extra_tests/snippets/builtin_type.py index 4f0581eed..a82c87e6c 100644 --- a/extra_tests/snippets/builtin_type.py +++ b/extra_tests/snippets/builtin_type.py @@ -151,3 +151,10 @@ assert BaseException.args.__qualname__ == 'BaseException.args' assert Exception.args.__qualname__ == 'BaseException.args' # dynamic with `.new_readonly_getset` assert SyntaxError.msg.__qualname__ == 'SyntaxError.msg' + + +# Regression to +# https://github.com/RustPython/RustPython/issues/2794 + +assert type.__subclasshook__.__qualname__ == 'type.__subclasshook__' +assert object.__subclasshook__.__qualname__ == 'object.__subclasshook__' diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 7cd4789e2..11f412c22 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -290,6 +290,11 @@ impl PyType { subclass.issubclass(&zelf) } + #[pyclassmethod(magic)] + fn subclasshook(_args: FuncArgs, vm: &VirtualMachine) -> PyObjectRef { + vm.ctx.not_implemented() + } + #[pyproperty(magic)] fn name(&self) -> String { self.name.clone()