Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/vm/src/stdlib/_abc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Comment on lines +275 to +277

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply the fallback to the pure ABC backend

When callers explicitly use _py_abc.ABCMeta (a backend the standard suite exercises at Lib/test/test_abc.py:687-690), this native-only fallback is bypassed because Lib/_py_abc.py:95 still evaluates instance.__class__ directly. Such objects therefore still raise AttributeError with the pure backend, including after virtual registration, leaving the advertised 3.14.8 ABC fix incomplete; apply the fallback to that backend too.

Useful? React with 👍 / 👎.


// Check cache
if in_weak_set(&impl_data.cache, &subclass, vm)? {
Expand Down
25 changes: 25 additions & 0 deletions extra_tests/snippets/stdlib_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,28 @@ class SubConcrete(Concrete):
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
Loading