mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 10:44:36 +08:00
Fix native ABC checks when __class__ is missing (#9067)
Retain the native fallback and Python regression without modifying bundled Lib sources. Assisted-by: OpenAI Codex:model identifier unavailable
This commit is contained in:
1 parent
a10744303f
commit
37fdf4d2d9
2 files changed
+28
-1
No files matched your search
@@ -272,7 +272,9 @@ mod _abc {
|
||||
let impl_data = get_impl(&cls, vm)?;
|
||||
|
||||
// Get instance.__class__
|
||||
let subclass = instance.get_attr("__class__", vm)?;
|
||||
let subclass = vm
|
||||
.get_attribute_opt(&instance, "__class__")?
|
||||
.unwrap_or_else(|| instance.class().to_owned().into());
|
||||
|
||||
// Check cache
|
||||
if in_weak_set(&impl_data.cache, &subclass, vm)? {
|
||||
|
||||
@@ -36,3 +36,28 @@ assert not issubclass(tuple, CustomInterface)
|
||||
assert isinstance(Concrete(), CustomInterface)
|
||||
assert isinstance(SubConcrete(), CustomInterface)
|
||||
assert not isinstance((), CustomInterface)
|
||||
|
||||
|
||||
class NoClassAttribute:
|
||||
@property
|
||||
def __class__(self):
|
||||
raise AttributeError("no class attribute")
|
||||
|
||||
|
||||
instance = NoClassAttribute()
|
||||
assert not isinstance(instance, CustomInterface)
|
||||
CustomInterface.register(NoClassAttribute)
|
||||
assert isinstance(instance, CustomInterface)
|
||||
|
||||
class_error = RuntimeError("class lookup failed")
|
||||
|
||||
|
||||
class BrokenClassAttribute:
|
||||
@property
|
||||
def __class__(self):
|
||||
raise class_error
|
||||
|
||||
|
||||
with assert_raises(RuntimeError) as caught:
|
||||
isinstance(BrokenClassAttribute(), CustomInterface)
|
||||
assert caught.exception is class_error
|
||||
Reference in new issue
Block a user