Issue 30620: textwrap: dedent contains logic that can never execute (original) (raw)

Issue30620

Created on 2017-06-10 04:09 by jonathaneunice, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2064 merged jonathaneunice,2017-06-10 04:17
Messages (4)
msg295606 - (view) Author: Jonathan Eunice (jonathaneunice) * Date: 2017-06-10 04:09
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.
msg295731 - (view) Author: Emily Morehouse (emilyemorehouse) * (Python committer) Date: 2017-06-11 21:36
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.
msg295733 - (view) Author: Emily Morehouse (emilyemorehouse) * (Python committer) Date: 2017-06-11 23:23
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.
msg296145 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-16 02:19
New changeset 7a801839e9a88bdcac5aaab494b532230fcf7caa by Mariatta (Jonathan Eunice) in branch 'master': bpo-30620: Remove dead lines from textwrap.dedent (GH-2064) https://github.com/python/cpython/commit/7a801839e9a88bdcac5aaab494b532230fcf7caa
History
Date User Action Args
2022-04-11 14:58:47 admin set github: 74805
2017-06-16 02:22:31 Mariatta set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-06-16 02:19:45 Mariatta set nosy: + Mariattamessages: +
2017-06-12 04:38:40 Mariatta set stage: patch review
2017-06-11 23:23:08 emilyemorehouse set nosy: + serhiy.storchakamessages: +
2017-06-11 22:29:28 rhettinger set assignee: emilyemorehouse
2017-06-11 21:36:44 emilyemorehouse set nosy: + emilyemorehousemessages: +
2017-06-10 04:17:35 jonathaneunice set pull_requests: + <pull%5Frequest2126>
2017-06-10 04:09:38 jonathaneunice create