Merge pull request #1216 from ethereum/fix-type-aliasing
Change uint aliases to just be subclasses
This commit is contained in:
commit
ab012b8adf
|
@ -130,11 +130,7 @@ def objects_to_spec(functions: Dict[str, str],
|
||||||
new_type_definitions = (
|
new_type_definitions = (
|
||||||
'\n\n'.join(
|
'\n\n'.join(
|
||||||
[
|
[
|
||||||
f"class {key}({value}):\n"
|
f"class {key}({value}):\n pass\n"
|
||||||
f" def __init__(self, _x: {value}) -> None:\n"
|
|
||||||
f" ...\n"
|
|
||||||
if value.startswith("uint")
|
|
||||||
else f"class {key}({value}):\n pass\n"
|
|
||||||
for key, value in custom_types.items()
|
for key, value in custom_types.items()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,7 +34,7 @@ class BasicValue(int, SSZValue, metaclass=BasicType):
|
||||||
class Bool(BasicValue): # can't subclass bool.
|
class Bool(BasicValue): # can't subclass bool.
|
||||||
byte_len = 1
|
byte_len = 1
|
||||||
|
|
||||||
def __new__(cls, value, *args, **kwargs):
|
def __new__(cls, value: int): # int value, but can be any subclass of int (bool, Bit, Bool, etc...)
|
||||||
if value < 0 or value > 1:
|
if value < 0 or value > 1:
|
||||||
raise ValueError(f"value {value} out of bounds for bit")
|
raise ValueError(f"value {value} out of bounds for bit")
|
||||||
return super().__new__(cls, value)
|
return super().__new__(cls, value)
|
||||||
|
@ -54,7 +54,7 @@ class Bit(Bool):
|
||||||
|
|
||||||
class uint(BasicValue, metaclass=BasicType):
|
class uint(BasicValue, metaclass=BasicType):
|
||||||
|
|
||||||
def __new__(cls, value, *args, **kwargs):
|
def __new__(cls, value: int):
|
||||||
if value < 0:
|
if value < 0:
|
||||||
raise ValueError("unsigned types must not be negative")
|
raise ValueError("unsigned types must not be negative")
|
||||||
if cls.byte_len and value.bit_length() > (cls.byte_len << 3):
|
if cls.byte_len and value.bit_length() > (cls.byte_len << 3):
|
||||||
|
|
Loading…
Reference in New Issue