Skip to content

Commit 3f5566d

Browse files
committed
Fix _typing.override
1 parent c0b9694 commit 3f5566d

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

Lib/test/test_typing.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,8 +3351,6 @@ def x(self): ...
33513351
self.assertNotIsSubclass(C, Protocol)
33523352
self.assertNotIsInstance(C(), Protocol)
33533353

3354-
# TODO: RUSTPYTHON
3355-
@unittest.expectedFailure
33563354
def test_protocols_issubclass_non_callable(self):
33573355
class C:
33583356
x = 1
@@ -3412,8 +3410,6 @@ def __init__(self) -> None:
34123410
):
34133411
issubclass(Eggs, Spam)
34143412

3415-
# TODO: RUSTPYTHON
3416-
@unittest.expectedFailure
34173413
def test_no_weird_caching_with_issubclass_after_isinstance_2(self):
34183414
@runtime_checkable
34193415
class Spam(Protocol):
@@ -3434,8 +3430,6 @@ class Eggs: ...
34343430
):
34353431
issubclass(Eggs, Spam)
34363432

3437-
# TODO: RUSTPYTHON
3438-
@unittest.expectedFailure
34393433
def test_no_weird_caching_with_issubclass_after_isinstance_3(self):
34403434
@runtime_checkable
34413435
class Spam(Protocol):

vm/src/stdlib/typing.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ pub(crate) mod decl {
4848
#[pyfunction(name = "override")]
4949
pub(crate) fn r#override(func: PyObjectRef, vm: &VirtualMachine) -> PyResult {
5050
// Set __override__ attribute to True
51-
func.set_attr("__override__", vm.ctx.true_value.clone(), vm)?;
51+
// Skip the attribute silently if it is not writable.
52+
// AttributeError happens if the object has __slots__ or a
53+
// read-only property, TypeError if it's a builtin class.
54+
let _ = func.set_attr("__override__", vm.ctx.true_value.clone(), vm);
5255
Ok(func)
5356
}
5457

0 commit comments

Comments
 (0)