-
Notifications
You must be signed in to change notification settings - Fork 997
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
SSZ implementation for exec. spec - Support for Python 3 typing. #1077
Conversation
Let's don't forget about our oldest current open spec PR: #695 (from before executable-spec time 😂). We finally get to do SSZ typing well with this PR, and have static-type checking in the spec. 🎉 |
I'm pro |
I tried this and it actually didn't work:
So the approach I was assuming we would take here is that plain int objects would be uint64's, and all other types of uints would need a wrapper class like
Great! Will change.
Agree! Will change. |
Questions:
--
|
Right. It works for Vector, but List is very different. List is from the typing package, and more of an add-on to make a normal list appear to be typed. from typing import List, NewType
print(issubclass(List, list))
print(issubclass(List[str], list))
print(issubclass(list, List))
# print(issubclass(list, List[str])) # TypeError: Parameterized generics cannot be used with class or instance checks
uint8 = NewType('uint8', int)
print(issubclass(List[uint8], list))
# print(issubclass(list, List[uint8])) # TypeError: Parameterized generics cannot be used with class or instance checks Prints all I can't seem to reproduce your error however. I wonder if it's the Python version, or something else. Here's the current Vector behavior: print(issubclass(Vector, Vector))
print(issubclass(Vector[str, 123], Vector))
print(issubclass(Vector, Vector[str, 123]))
uint8 = NewType('uint8', int)
print(issubclass(Vector[uint8, 123], Vector))
print(issubclass(Vector, Vector[uint8, 123])) False
True
False
True
False We may want to change the behavior of |
Sort of. We use
One work-around would be to default to
See above comment on custom
It does work. But yes, it is super hacky. But the alternative of boxing integers doesn't sound great either. Maybe we can just go for the default |
…format and default param equals without spaces warnings
@hwwhww The CI doesn't see the flake8 version in the Makefile (I updated it) since it's not in the requirements file (where the checksum is taken from), and still uses the old cached flake8, with bugged linting for type annotations. :( All issues (merge conflicts, testing, linting) resolved. Just need the partials finished + conforming to PEP-8, and we can get this merged. |
Had to fix a dependency issue (fixed in commit 8e8ef2d), but verified that the |
@hwwhww Fixed the linting caching problem. Can we get this PR into final review, then merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor comments. Awesome python wizardry!
I did not do a deep review of generalized indices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Witchcraft! 🧙♂️
I only went through ssz_typing.py
!
I’d (strongly) suggest moving the new merkle_minimal.py
and ssz_partials.py
to another PR so that it could get a proper review.
Co-Authored-By: Danny Ryan <[email protected]>
Co-Authored-By: Danny Ryan <[email protected]>
Ran the SSZ static generators again, and they result in the same test-vectors as running the generator on the |
The partials implementation is moved out to the |
I'm working on tests now, and shifted away from the SSZ readability/typing ambitions after my POC presented in #1064. I hope others can pick up the SSZ typing idea now, with this code ready to transform the spec. See comments in issue.Finished it (testing PRs feature-wise complete, merging coming along, I got to work on SSZ again)What still needs work:
less hacky spec builder / type field translationcheck that when constants are changed (config override), types adapt. Otherwise, re-introduce the re-init function we have now for old non-python type system.Introduced re-init function back. May explore module-reloading as alternative later, after phase-1 spec-building is in.fix integer/bytesN types being recognized or not. Just need to be unique declarations to work for the SSZ matching code. Otherwise no-overhead int/bytes objects. (Or maybe Dankrad wants to box them anyway for bounds checking?)int
default to uint64, and don't have to worry about ugly slow integer boxes in 99% of the spec.make it run outside of POC setting, in exec. spec. minor detail.Fixed it. Thessz_static
build output now matches that of dev, but with a type based ssz system 🎉