textwrap.dedent contains a bit of code that appears logical at first blush, but in fact can never execute under any input conditions. Not only are the lines "dead code," they are the only thing (i.e. only non-debugging lines) now standing in the way of textwrap having 100% test coverage. Here is the proof: https://gist.github.com/jonathaneunice/86f6a721e48c89e272a778530e8f758c A PR removing the bogus lines is imminent.
The logic in your proof is certainly sound. The only time that the else statement within Clause 4 (to use terminology from the proof) would execute is either 1) if margin is equal to indent, which is handled in Clause 2, or 2) if the margin is None, which is handled in Clause 1. I support this PR. On a related note, I feel that the existing comments could clearer illustrate this. Specifically, it is unclear that Clause 2 will also catch cases where margin and indent are equal.
Jonathan, could you improve the comments for the dedent function? You have a great understanding of the logic flow from your proof and it would be beneficial to document this to avoid future confusion. Specifically, it should be clear that Clause 2 inherently handles equivalence for margin and indent and that Clause 4 will always complete with the break statement.