Title: Argparse wrapping is bugged when colors are involved · Issue #142035 · python/cpython · GitHub
Open Graph Title: Argparse wrapping is bugged when colors are involved · Issue #142035 · python/cpython
X Title: Argparse wrapping is bugged when colors are involved · Issue #142035 · python/cpython
Description: Bug report Bug description: While working on coloring interpolated values in #141940, I realized that in some cases the wrapping is broken. For example in this case, just a color change around the commas makes the wrapping different, bec...
Open Graph Description: Bug report Bug description: While working on coloring interpolated values in #141940, I realized that in some cases the wrapping is broken. For example in this case, just a color change around the ...
X Description: Bug report Bug description: While working on coloring interpolated values in #141940, I realized that in some cases the wrapping is broken. For example in this case, just a color change around the ...
Opengraph URL: https://github.com/python/cpython/issues/142035
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Argparse wrapping is bugged when colors are involved","articleBody":"# Bug report\n\n### Bug description:\n\nWhile working on coloring interpolated values in #141940, I realized that in some cases the wrapping is broken.\n\nFor example in this case, just a color change around the commas makes the wrapping different, because `textwrap.wrap` is sensitive to ANSI escape codes (those change the string length).\n\n\u003cimg width=\"389\" height=\"52\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/bd0e36c6-922e-47d9-8f52-8431b55adc61\" /\u003e\n\nThere are 2 ways to fix this:\n* have a more clever wrapping that is not sensitive to ANSI escape codes\n* make sure the wrapping always happens before ANSI escape codes are inserted\n\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nmacOS\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-142040\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/alexprengere","@type":"Person","name":"alexprengere"},"datePublished":"2025-11-28T09:46:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/142035/cpython/issues/142035"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c0d28055-f680-208e-e1b6-7dd0f3b87b66 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C504:11169F:1FB53FC:299A782:696B06EC |
| html-safe-nonce | 68b906213312a3cc8f32eb7d53de2d625ff2542e84ffc54ce7af9aa788038805 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTA0OjExMTY5RjoxRkI1M0ZDOjI5OUE3ODI6Njk2QjA2RUMiLCJ2aXNpdG9yX2lkIjoiODk1MDM2NzEyODI2MjQ3NzU0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 73d1cf6b229bbd1eefce0dd201914105b6c724a5c6aced8acc02675a1e9a92ea |
| hovercard-subject-tag | issue:3674271382 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/142035/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5f50b6184f9820edbb849f97e1647bfbe3d40373669c92ebcce48eebef133adc/python/cpython/issues/142035 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5f50b6184f9820edbb849f97e1647bfbe3d40373669c92ebcce48eebef133adc/python/cpython/issues/142035 |
| og:image:alt | Bug report Bug description: While working on coloring interpolated values in #141940, I realized that in some cases the wrapping is broken. For example in this case, just a color change around the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexprengere |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width