circuitpython/tests/cpydiff/types_int_subclassconv.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

15 lines
338 B
Python
Raw Permalink Normal View History

"""
categories: Types,int
description: No int conversion for int-derived types available
cause: Unknown
workaround: Avoid subclassing builtin types unless really needed. Prefer https://en.wikipedia.org/wiki/Composition_over_inheritance .
"""
2021-03-15 09:57:36 -04:00
class A(int):
__add__ = lambda self, other: A(int(self) + other)
2021-03-15 09:57:36 -04:00
a = A(42)
2021-03-15 09:57:36 -04:00
print(a + a)