Fix checking multiple assignments based on tuple unpacking involving partially initialised variables (Fixes #12915).
Fix checking multiple assignments based on tuple unpacking involving partially initialised variables (Fixes #12915).
This commit introduces two changes:
- It converts unions of tuples to tuples of unions during multi-assignment checking when all (original) tuples have the same length. This fixes #12915.
- It removes the
undefined_rvaluelogic completely. This logic bothered me because it introduced the necessity to make the mentioned conversion twice (which was not always successful due to reasons I do not fully understand).
Test new case testDefinePartiallyInitialisedVariableDuringTupleUnpacking covers issue #12915.
I had to adjust some other test cases. In my opinion, the error messages are now more transparent, consistent, and complete. Removing the undefined_rvalue logic also seems to fix one more bug. In the test cases testInferenceWithTypeVariableTwiceInReturnType and testInferenceWithTypeVariableTwiceInReturnTypeAndMultipleVariables, there were three assignments for which Mypy did not report errors but, in my opinion, should.
So, for the current test data set, removing the undefined_rvalue logic seems to introduce mere benefits than drawbacks (meaning, different error messages than before). I hope it does not break any Mypy functionalities not covered by the tests.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
After rethinking my approach, I decided to extend it to cover unions containing other iterable items. The result is #14440, which involves even more changes than this pull request. I consider #14440 better but leave this one open if I am wrong.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉