Title: `reprlib.Repr` truncation ignores the length of a custom `fillvalue` · Issue #161289 · python/cpython · GitHub
Open Graph Title: `reprlib.Repr` truncation ignores the length of a custom `fillvalue` · Issue #161289 · python/cpython
X Title: `reprlib.Repr` truncation ignores the length of a custom `fillvalue` · Issue #161289 · python/cpython
Description: Bug report Bug description: Since Python 3.11, reprlib.Repr.fillvalue can be set to any string, but Repr.repr_str(), Repr.repr_int() and Repr.repr_instance() still compute how many characters to keep around it as if it were always three ...
Open Graph Description: Bug report Bug description: Since Python 3.11, reprlib.Repr.fillvalue can be set to any string, but Repr.repr_str(), Repr.repr_int() and Repr.repr_instance() still compute how many characters to ke...
X Description: Bug report Bug description: Since Python 3.11, reprlib.Repr.fillvalue can be set to any string, but Repr.repr_str(), Repr.repr_int() and Repr.repr_instance() still compute how many characters to ke...
Opengraph URL: https://github.com/python/cpython/issues/161289
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`reprlib.Repr` truncation ignores the length of a custom `fillvalue`","articleBody":"### Bug report\n\n### Bug description:\n\nSince Python 3.11, `reprlib.Repr.fillvalue` can be set to any string, but `Repr.repr_str()`, `Repr.repr_int()` and `Repr.repr_instance()` still compute how many characters to keep around it as if it were always three characters long (the length of the default `'...'`):\n\n```python\ni = max(0, (self.maxstring-3)//2)\nj = max(0, self.maxstring-3-i)\ns = s[:i] + self.fillvalue + s[len(s)-j:]\n```\n\nAs a result, when the fill value has a different length, a truncated representation no longer fits `maxstring`, `maxlong` or `maxother`:\n\n```python\n>>> import reprlib\n>>> r = reprlib.Repr(maxstring=10, maxlong=10, maxother=10, fillvalue='\u003csnip>')\n>>> r.repr(12345678901234567890) # 13 characters, maxlong is 10\n'123\u003csnip>7890'\n>>> r.repr('abcdefghijklmnopqrstuvwxyz') # 13 characters, maxstring is 10\n\"'ab\u003csnip>xyz'\"\n>>> r = reprlib.Repr(maxstring=10, fillvalue='…')\n>>> r.repr('abcdefghijklmnopqrstuvwxyz') # 8 characters, 2 left unused\n\"'ab…xyz'\"\n```\n\nThe documentation describes `maxlong` as the \"Maximum number of characters in the representation for an integer\". Using `len(self.fillvalue)` instead of `3` makes the result fit the limit, and leaves the output with the default `'...'` unchanged.\n\n### CPython versions tested on:\n\n3.12, 3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-161290\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/andresdelfino","@type":"Person","name":"andresdelfino"},"datePublished":"2026-11-04T01:19:31Z","url":"https://github.com/python/cpython/issues/161289"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:b77dd6de-cdcb-d64f-39d4-0a2507f9420d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B522:1F2B:2D291:40F44:6B02025F |
| html-safe-nonce | 160a66953d34aee7cba50f6e1c1705fb672baed694bc659647840de4639581d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTIyOjFGMkI6MkQyOTE6NDBGNDQ6NkIwMjAyNUYiLCJ2aXNpdG9yX2lkIjoiODU1ODExMDgyMzE2MjE4NDI4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | df1aade6a79091ac6b9aab634363a4880bc0222ed705e6d1f54c25ac49733df8 |
| hovercard-subject-tag | issue:6194313491 |
| 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/161289/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1dcf3b68aed5e54b68b235e486c52f138e2397c03788831abb7a2b4d71be0817/python/cpython/issues/161289 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1dcf3b68aed5e54b68b235e486c52f138e2397c03788831abb7a2b4d71be0817/python/cpython/issues/161289 |
| og:image:alt | Bug report Bug description: Since Python 3.11, reprlib.Repr.fillvalue can be set to any string, but Repr.repr_str(), Repr.repr_int() and Repr.repr_instance() still compute how many characters to ke... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | andresdelfino |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| 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 | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width