Merge pull request #2821 from sobolevn/issue-2794

Adds `__subclasshook__` to `type`
This commit is contained in:
Jim Fasarakis-Hilliard
2021-08-09 17:54:56 +03:00
committed by GitHub
2 changed files with 12 additions and 0 deletions

View File

@@ -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__'

View File

@@ -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()