You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specify fixed number of elements in the tuple #221
Greetings! Currently I am moving cryptographic library from Python2/3 to mypy. I have got so-called S-box-es: tuple consisting of 8 tuples with 16 integers inside. Like this:
There's no better way to specify a constant-length tuple. I'd recommend considering Tuple[int, ...] (literal ...) for a variable-length tuple, though, as the extra type checking you might get from having a constant-length tuple might not be worth the awkward type.
There is no way to specify the length of a bytes object (or a list, for that matter).
Activity
JukkaL commentedon May 16, 2016
There's no better way to specify a constant-length tuple. I'd recommend considering
Tuple[int, ...](literal...) for a variable-length tuple, though, as the extra type checking you might get from having a constant-length tuple might not be worth the awkward type.There is no way to specify the length of a
bytesobject (or a list, for that matter).aldanor commentedon Aug 13, 2016
@stargrave A bit late to this issue, but you can always do this:
gvanrossum commentedon Aug 13, 2016
aldanor commentedon Aug 13, 2016
Ah, apologies then, it works with typing but didn't realise mypy would choke on that.