-
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
Add SSZ utils to mypy checking scope #1707
base: dev
Are you sure you want to change the base?
Conversation
I'll look into Mypy for remerkleable. The tricky part here is that integers in generics don't work in python without the verbosity of The powerful part of Python to me is not its type checking or concurrency (both only have workarounds, not actual solutions). It's the ability to script and express things with minimal overhead. Syntax sugar and ability to define and interact easily with SSZ and the spec are special; no other client/tool makes it that easy to build/test some consensus thing. I am happy to introduce typing closer to mypy, but prefer not to reduce Python to Java. Also, we can definitely make more constants typed, but I also like the idea of constants getting their type automatically from their usage. But that may be too much of a Go-lang thing. |
@protolambda |
Issue
--ignore-missing-imports
was True and--disallow-subclassing-any
wasFalse
, from pyspec side, it considers the types (e.g.,uint64
,Bytes32
,Container
) from the un-mypy-izedremerkleable
areAny
. (See: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-disallow-subclassing-any for the details)uint64
. Stricter mypy setting can help us to detect the required conversion.This current draft PR:
lint
configuration changes in Makefile and mypy configuration filemypy.ini
.stubgen
to create theremerkleable
andeth2spec.utils.ssz
mypy stubs.Error log: https://gist.github.com/hwwhww/cacdaa8842ec62241c8ff03e1ca56ba3
Things we can do to clean the errors and improve the typings:
eth2spec/phase0/spec.py:466: error: Argument 1 to "int_to_bytes" has incompatible type "int"; expected "uint64"
eth2spec/phase0/spec.py:48: error: Class cannot subclass 'Bytes32' (has type 'Any')
onclass Root(Bytes32): pass
:remerkleable
, or we can try to ignore it.Variable "eth2spec.phase0.spec.MAX_VALIDATORS_PER_COMMITTEE" is not valid as a type
onattesting_indices: List[ValidatorIndex, MAX_VALIDATORS_PER_COMMITTEE]
:remerkleable
typing, or we can try to ignore it.@protolambda what do you think about the stricter SSZ typing checks? :)