Title: Incompatible (wrt floats) processing of alignment and '0' flag in Fraction's formatting · Issue #130716 · python/cpython · GitHub
Open Graph Title: Incompatible (wrt floats) processing of alignment and '0' flag in Fraction's formatting · Issue #130716 · python/cpython
X Title: Incompatible (wrt floats) processing of alignment and '0' flag in Fraction's formatting · Issue #130716 · python/cpython
Description: Bug report Bug description: >>> x = Fraction(1, 3) >>> f"{x:_>010f}" Traceback (most recent call last): File "
Open Graph Description: Bug report Bug description: >>> x = Fraction(1, 3) >>> f"{x:_>010f}" Traceback (most recent call last): File "
X Description: Bug report Bug description: >>> x = Fraction(1, 3) >>> f"{x:_>010f}" Traceback (most recent call last): File "<python-input-2>", line 1, in <module...
Opengraph URL: https://github.com/python/cpython/issues/130716
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incompatible (wrt floats) processing of alignment and '0' flag in Fraction's formatting","articleBody":"# Bug report\n\n### Bug description:\n\n```pycon\n\u003e\u003e\u003e x = Fraction(1, 3)\n\u003e\u003e\u003e f\"{x:_\u003e010f}\"\nTraceback (most recent call last):\n File \"\u003cpython-input-2\u003e\", line 1, in \u003cmodule\u003e\n f\"{x:_\u003e010f}\"\n ^^^^^^^^^^\n File \"/home/sk/src/cpython/Lib/fractions.py\", line 600, in __format__\n raise ValueError(\n ...\u003c2 lines\u003e...\n )\nValueError: Invalid format specifier '_\u003e010f' for object of type 'Fraction'\n\u003e\u003e\u003e f\"{float(x):_\u003e010f}\"\n'__0.333333'\n```\nWhile not being documented, this behavior is intentional (see https://github.com/python/cpython/pull/100161): \"The Fraction formatter is also stricter about combining these two things: it's not permitted to use both the '0' flag and explicit alignment, on the basis that we should refuse the temptation to guess in the face of ambiguity.\" In floats case, \"0\" flag is just ignored if the fill character (and, thus, alignment) already specified.\n\nMaybe it's not a bad idea to use Fraction's behavior for floats too, i.e. deprecate this silent resolution of ambiguity. Or just document this discrepancy.\n\nDecimal's behave here like Fraction's:\n```pycon\n\u003e\u003e\u003e f\"{Decimal(1.25):_\u003e010f}\"\nTraceback (most recent call last):\n File \"\u003cpython-input-5\u003e\", line 1, in \u003cmodule\u003e\n f\"{Decimal(1.25):_\u003e010f}\"\n ^^^^^^^^^^^^^^^^^^^^^^\nValueError: invalid format string\n```\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\n_No response_","author":{"url":"https://github.com/skirpichev","@type":"Person","name":"skirpichev"},"datePublished":"2025-03-01T01:51:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/130716/cpython/issues/130716"}
| 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:4b66cce5-0ca7-082f-5389-99dc504e45a9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B870:D707E:4571FE:61F05A:696A0B8B |
| html-safe-nonce | e7257941946b4f7e6b9664badf411c44104848d6c4507a1888d9c15f74af8d1c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODcwOkQ3MDdFOjQ1NzFGRTo2MUYwNUE6Njk2QTBCOEIiLCJ2aXNpdG9yX2lkIjoiNjY3OTc2OTM4NTE4Mzg3MzkzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f72bcfa3047c8898a721ee93112b51aedfbc88c3f5f0239bd09de89c71763e59 |
| hovercard-subject-tag | issue:2888379597 |
| 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/130716/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e6a32ed1b2121c136047af5a1743a6fa743323de9985ae50caebc61c24a7ed9a/python/cpython/issues/130716 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e6a32ed1b2121c136047af5a1743a6fa743323de9985ae50caebc61c24a7ed9a/python/cpython/issues/130716 |
| og:image:alt | Bug report Bug description: >>> x = Fraction(1, 3) >>> f"{x:_>010f}" Traceback (most recent call last): File " |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | skirpichev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| 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 | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width