python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.49k stars 2.83k forks source link

Mypy cannot handle different literal boolean values #16829

Open PythonCoderAS opened 9 months ago

PythonCoderAS commented 9 months ago

If you define all overloaded cases for different boolean variables, Mypy still complains about overloaded functions having non-overlapping return types.

(A clear and concise description of what the bug is.)

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.12&gist=c335d619eb28830e11ccc147bb974752

Actual Behavior

main.py:5: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [overload-overlap]
main.py:5: error: Overloaded function signatures 1 and 3 overlap with incompatible return types  [overload-overlap]
main.py:5: error: Overloaded function signatures 1 and 4 overlap with incompatible return types  [overload-overlap]
main.py:10: error: Overloaded function signatures 2 and 3 overlap with incompatible return types  [overload-overlap]
main.py:10: error: Overloaded function signatures 2 and 4 overlap with incompatible return types  [overload-overlap]
main.py:17: error: Overloaded function signatures 3 and 4 overlap with incompatible return types  [overload-overlap]
Found 6 errors in 1 file (checked 1 source file)

Your Environment

tmke8 commented 9 months ago

The problem is that you made all arguments optional by giving them default values. This means all overloads match an invocation without any arguments. And it's also wrong: the arguments never have True as the default value in your implementation. If you remove = True everywhere, it works: https://mypy-play.net/?mypy=latest&python=3.12&gist=33e891d0d674a04be9de77239fa12bfd