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: Octal byte literals with a decimal value > 255 are silently truncated
Type: behavior Stage:
Components: Interpreter Core, Windows Versions: Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bup, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2018-09-10 11:57 by bup, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg324918 - (view) Author: Dan Snider (bup) * Date: 2018-09-10 11:57
>>> b'\542\571\564\545\563', b'\142\171\164\145\163'
(b'bytes', b'bytes')

All the C compilers I know of at the very least generate a warning when one tries to assign an oct literal >= '\400' to a byte. And that's because it's nonsense when bytes have 8 bits, even more so for an 8 bit byte string.

The literal value:

>>> b'\542\571\564\545\563'

should be identical to:

>>> bytes([0o542, 0o571, 0o564, 0o545, 0o563])

That obviously doesn't work:

>>> b'\542\571\564\545\563' == bytes([0o542, 0o571, 0o564, 0o545, 0o563])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: bytes must be in range(0, 256)

This is on Windows/Intel. I haven't looked at the parser in much detail, but I wonder what would happen on a big-endian system?
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78801
2018-09-10 11:57:43bupcreate