bpo-31780: Fix incorrect message for format spec by pablogsal · Pull Request #4002 · python/cpython (original) (raw)

As can be checked in the discussion for bpo-31780 there is an incorrect error message when using the ',b', ',o' or ',x' formatters:

i = 10000 for base in 'box': for sep in ',_': try: print(f'{i:{sep}{base}}') except ValueError as err: print(repr(err))

ValueError("Cannot specify ',' or '' with 'b'.",) 1_1000_0110_1010_0000 ValueError("Cannot specify ',' or '' with 'o'.",) 30_3240 ValueError("Cannot specify ',' or '_' with 'x'.",) 1_86a0

This PR fixes this so now we obtain:

i = 10000 for base in 'box': for sep in ',_': try: print(f'{i:{sep}{base}}') except ValueError as err: print(repr(err))

ValueError("Cannot specify ',' with 'b'.",) 1_1000_0110_1010_0000 ValueError("Cannot specify ',' with 'o'.",) 30_3240 ValueError("Cannot specify ',' with 'x'.",) 1_86a0

https://bugs.python.org/issue31780