This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: textwrap: dedent contains logic that can never execute
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: emilyemorehouse Nosy List: Mariatta, emilyemorehouse, jonathaneunice, serhiy.storchaka
Priority: normal Keywords:

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:47adminsetgithub: 74805
2017-06-16 02:22:31Mariattasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-06-16 02:19:45Mariattasetnosy: + Mariatta
messages: + msg296145
2017-06-12 04:38:40Mariattasetstage: patch review
2017-06-11 23:23:08emilyemorehousesetnosy: + serhiy.storchaka
messages: + msg295733
2017-06-11 22:29:28rhettingersetassignee: emilyemorehouse
2017-06-11 21:36:44emilyemorehousesetnosy: + emilyemorehouse
messages: + msg295731
2017-06-10 04:17:35jonathaneunicesetpull_requests: + pull_request2126
2017-06-10 04:09:38jonathaneunicecreate