Код: Выделить всё
from typing import ClassVar, TypeVar
from hypothesis import strategies as st
T = TypeVar("T", bound="FixedUint")
class FixedUint(int):
MAX_VALUE: ClassVar["FixedUint"]
def __init__(self: T, value: int) -> None:
if not isinstance(value, int):
raise TypeError()
if value < 0 or value > self.MAX_VALUE:
raise OverflowError()
class U256(FixedUint):
pass
U256.MAX_VALUE = int.__new__(U256, (2**256) - 1)
class U64(FixedUint):
pass
U64.MAX_VALUE = int.__new__(U64, (2**64) - 1)
st.from_type(U64).example()
# TypeError: 'value' is an invalid keyword argument for int()
Как это сделать?
Подробнее здесь: https://stackoverflow.com/questions/791 ... t-subclass
Мобильная версия