Fix _typing.override

This commit is contained in:
Jeong YunWon
2025-06-26 18:33:13 +09:00
parent c0b9694cda
commit 3f5566da53
2 changed files with 4 additions and 7 deletions

View File

@@ -3351,8 +3351,6 @@ class ProtocolTests(BaseTestCase):
self.assertNotIsSubclass(C, Protocol)
self.assertNotIsInstance(C(), Protocol)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_protocols_issubclass_non_callable(self):
class C:
x = 1
@@ -3412,8 +3410,6 @@ class ProtocolTests(BaseTestCase):
):
issubclass(Eggs, Spam)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_weird_caching_with_issubclass_after_isinstance_2(self):
@runtime_checkable
class Spam(Protocol):
@@ -3434,8 +3430,6 @@ class ProtocolTests(BaseTestCase):
):
issubclass(Eggs, Spam)
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_no_weird_caching_with_issubclass_after_isinstance_3(self):
@runtime_checkable
class Spam(Protocol):

View File

@@ -48,7 +48,10 @@ pub(crate) mod decl {
#[pyfunction(name = "override")]
pub(crate) fn r#override(func: PyObjectRef, vm: &VirtualMachine) -> PyResult {
// Set __override__ attribute to True
func.set_attr("__override__", vm.ctx.true_value.clone(), vm)?;
// Skip the attribute silently if it is not writable.
// AttributeError happens if the object has __slots__ or a
// read-only property, TypeError if it's a builtin class.
let _ = func.set_attr("__override__", vm.ctx.true_value.clone(), vm);
Ok(func)
}