mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
py/runtime: Fix bool unary op for subclasses of native types.
Previously a subclass of a type that didn't implement unary_op, or didn't handle MP_UNARY_OP_BOOL, would raise TypeError on bool conversion. Fixes #5677.
This commit is contained in:
committed by
Damien George
parent
14b853eae0
commit
4e39ff221a
@@ -23,5 +23,12 @@ print(not A())
|
||||
# check user instances derived from builtins
|
||||
class B(int): pass
|
||||
print(not B())
|
||||
print(True if B() else False)
|
||||
class C(list): pass
|
||||
print(not C())
|
||||
print(True if C() else False)
|
||||
# type doesn't define unary_op
|
||||
class D(type): pass
|
||||
d = D("foo", (), {})
|
||||
print(not d)
|
||||
print(True if d else False)
|
||||
|
||||
Reference in New Issue
Block a user