Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change uint aliases to just be subclasses #1216

Merged
merged 3 commits into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions scripts/build_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ def objects_to_spec(functions: Dict[str, str],
new_type_definitions = (
'\n\n'.join(
[
f"class {key}({value}):\n"
f" def __init__(self, _x: {value}) -> None:\n"
f" ...\n"
if value.startswith("uint")
else f"class {key}({value}):\n pass\n"
f"class {key}({value}):\n pass\n"
for key, value in custom_types.items()
]
)
Expand Down
2 changes: 1 addition & 1 deletion specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ def is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool:

# Count active validators at genesis
active_validator_count = 0
for validator in state.validator_registry:
for validator in state.validators:
if validator.effective_balance == MAX_EFFECTIVE_BALANCE:
active_validator_count += 1

Expand Down
4 changes: 2 additions & 2 deletions test_libs/pyspec/eth2spec/utils/ssz/ssz_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class BasicValue(int, SSZValue, metaclass=BasicType):
class Bool(BasicValue): # can't subclass bool.
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:
raise ValueError(f"value {value} out of bounds for bit")
return super().__new__(cls, value)
Expand All @@ -54,7 +54,7 @@ class Bit(Bool):

class uint(BasicValue, metaclass=BasicType):

def __new__(cls, value, *args, **kwargs):
def __new__(cls, value: int):
if value < 0:
raise ValueError("unsigned types must not be negative")
if cls.byte_len and value.bit_length() > (cls.byte_len << 3):
Expand Down