pycryptodome icon indicating copy to clipboard operation
pycryptodome copied to clipboard

Mypy errors when mixing PyCryptodome integer type and Python int

Open dogtopus opened this issue 3 years ago • 0 comments

On https://github.com/Legrandin/pycryptodome/blob/5dace638b70ac35bb5d9b565f3e75f7869c9d851/lib/Crypto/PublicKey/RSA.pyi#L41-L45 the RSA.construct() is defined to have tuple of Python ints only instead of also accepting PyCryptodome integer types (like IntegerGMP or just simply Integer). Mixing both int types throws Mypy off and it gives an incompatible variable type error.

Seems like it's fixable by defining a new integer type that is a union of Python int and IntegerBase (something like IntegerLike = Union[int, IntegerBase]) and use this new definition for crypto-related methods that accept both Python int and PyCryptodome integers.

dogtopus avatar May 14 '21 07:05 dogtopus