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

Non-substantive typing clean-up #2036

Merged
merged 1 commit into from
Sep 10, 2020
Merged

Non-substantive typing clean-up #2036

merged 1 commit into from
Sep 10, 2020

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Sep 3, 2020

  1. Add more type castings.
  2. Add uint64() castings to phase 1 constants and configurations.

@hwwhww hwwhww added the general:typing Spec typing, no breaking changes label Sep 3, 2020
@hwwhww hwwhww requested review from protolambda and djrtwo September 7, 2020 05:03
Copy link
Collaborator

@protolambda protolambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Hesitant about introducing PyList in spec
  • Agree with uint64/other types for constants
  • Some type casts in the code seem unnecessary, since they should automatically follow from the arithmetic typing rules of the ssz code.

PR looks good, but the balance between typing and readability/simplicity is getting blurry

@@ -773,7 +773,7 @@ def compute_committee(indices: Sequence[ValidatorIndex],
Return the committee corresponding to ``indices``, ``seed``, ``index``, and committee ``count``.
"""
start = (len(indices) * index) // count
end = (len(indices) * (index + 1)) // count
end = (len(indices) * uint64(index + 1)) // count
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this wouldn't be necessary anymore with the changes to remerkleable? uint64 + int -> uint64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message (#1707) was error: Need type annotation for 'end'. I think mypy couldn't determine the type here with static checks.

I can change it to end: uint64 = (len(indices) * (index + 1)) // count alternatively.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it works when you uint64(len(indices)) instead? I find it weird to coerce the result, instead of the inputs.

Comment on lines +284 to +286
shard_block_lengths = [] # type: PyList[uint64]
shard_data_roots = [] # type: PyList[Root]
shard_states = [] # type: PyList[ShardState]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyList was not meant to make it into the spec. More type safety is nice, but I am hesitant to introduce this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitant too, and intentionally used type comments instead of shard_block_lengths: PyList[uint64] = []. 😅 But I understand your concerns.

A "PyList is okay" argument is that we already have Python Set, Dict, and Tuple in the specs.

Would renaming PyList to Array be better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyList is okay then I guess. And sorry for nitpicking, it's just a style thing that we tried to avoid previously, but typing is more important.

Copy link
Collaborator

@protolambda protolambda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think it's important you can merge it, I don't want to hold this up longer than necessary. Just have a few style nitpicks.

@djrtwo djrtwo merged commit 54f1abc into dev Sep 10, 2020
@djrtwo djrtwo deleted the typing_clean branch September 10, 2020 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
general:typing Spec typing, no breaking changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants