Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-81548: Deprecate octal sequences with value larger than 0o377 #91668

Merged

Conversation

serhiy-storchaka
Copy link
Member

Closes #81548.

@gvanrossum
Copy link
Member

I'm glad you're doing this!

@serhiy-storchaka
Copy link
Member Author

Interesting, you posted your comment just between two commits which I have pushed with one git push.

@serhiy-storchaka serhiy-storchaka merged commit 3483299 into python:main Apr 30, 2022
@serhiy-storchaka serhiy-storchaka deleted the deprecate-invalid-octal-escape branch April 30, 2022 10:16
@slateny
Copy link
Contributor

slateny commented Apr 30, 2022

I think this line should be :gh: instead of :issue: - got a failed CI here

@disconnect3d
Copy link
Contributor

disconnect3d commented Feb 22, 2023

If possible, I would suggest extending the information about this deprecation warning as it is not obvious for people reading this why is this made and when does the deprecation warning fires off.

  1. The former could be something like:

This is done because high octal escape values may give unexpected results. For example the b'\407' literal is b'\x07' as the 0o407 (263) value is treated as a single byte and 263 % 256 = 7.

  1. The latter issue, when the deprecation warning fires off, can be seen here:
$ cat a.py
print("\407", b"\407")

$ python3.11 a.py
ć b'\x07'

$ python3.11 -W default a.py
//a.py:1: DeprecationWarning: invalid octal escape sequence '\407'
  print("\407", b"\407")
//a.py:1: DeprecationWarning: invalid octal escape sequence '\407'
  print("\407", b"\407")
ć b'\x07'

I believe this comes from the default warning filter. Idk if we really want it described there, but imho it never hurts to provide more information.

cc: @serhiy-storchaka

@pablogsal
Copy link
Member

If possible, I would suggest extending the information about this deprecation warning as it is not obvious for people reading this why is this made and when does the deprecation warning fires off.

  1. The former could be something like:

This is done because high octal escape values may give unexpected results. For example the b'\407' literal is b'\x07' as the 0o407 (263) value is treated as a single byte and 263 % 256 = 7.

  1. The latter issue, when the deprecation warning fires off, can be seen here:
$ cat a.py
print("\407", b"\407")

$ python3.11 a.py
ć b'\x07'

$ python3.11 -W default a.py
//a.py:1: DeprecationWarning: invalid octal escape sequence '\407'
  print("\407", b"\407")
//a.py:1: DeprecationWarning: invalid octal escape sequence '\407'
  print("\407", b"\407")
ć b'\x07'

I believe this comes from the default warning filter. Idk if we really want it described there, but imho it never hurts to provide more information.

cc: @serhiy-storchaka

Will give this a go soon 👍

@arhadthedev
Copy link
Member

Will give this a go soon 👍

@pablogsal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

octal escapes applied inconsistently throughout the interpreter and lib
7 participants