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
When returning a Union, you say "the code calling this function must be prepared for any of these". That's not how the new() function should work: it returns one specific kind of AES cipher, and I shouldn't need to worry about the other modes when using it.
If you want, I can submit a pull request that does this. It will be a lot of copy/paste though. python/typing#566 would also help, but it's just a proposal and far from being implemented in practice.
There are a few possible workarounds. I can make the type checker ignore the other union members with Any:
Thanks for flagging this error. There is an existing PR (#533) to address the problem by means of Literal (as you proposed) but it still not fully convincing yet.
This works at runtime, but fails to type check:
The mypy error is:
The stub that causes this problem is:
pycryptodome/lib/Crypto/Cipher/AES.pyi
Lines 31 to 44 in dfb16dd
When returning a
Union
, you say "the code calling this function must be prepared for any of these". That's not how thenew()
function should work: it returns one specific kind of AES cipher, and I shouldn't need to worry about the other modes when using it.To fix this, we could use overloads with
Literal
:If you want, I can submit a pull request that does this. It will be a lot of copy/paste though. python/typing#566 would also help, but it's just a proposal and far from being implemented in practice.
There are a few possible workarounds. I can make the type checker ignore the other union members with
Any
:Or just use
Any
for the whole thing (but then I get no type checker errors for wrong code):Or just ignore the error:
The text was updated successfully, but these errors were encountered: