Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reject invalid escape sequences (and octal escape sequences) in bytes and Unicode strings #98401

Closed
Labels
type-bugAn unexpected behavior, bug, or error
@vstinner

Description

@vstinner

In Python 3.6,invalid escape sequence were deprecated in string literals (bytes and str): issue#71551, commit110b6fe.

What's New in Python 3.6: Deprecated Python behavior:

A backslash-character pair that is not a valid escape sequence now generates a DeprecationWarning. Although this will eventually become a SyntaxError, that will not be for several Python releases. (Contributed by Emanuel Barry in bpo-27364.)

I propose now raises a SyntaxError, rather than a DeprecationWarning (which is silent in most cases).

Example:

$ python3 -W default -c 'print(list("\z"))'<string>:1: DeprecationWarning: invalid escape sequence '\z'['\\', 'z']$ python3 -W default -c 'print(list(b"\z"))'<string>:1: DeprecationWarning: invalid escape sequence '\z'[92, 122]

Note: Python REPL ate some DeprecationWarning which makes manual testing harder. It was fixed last month by commit426d72e in issuegh-96052.


Python 3.11 now emits a deprecation warning forinvalidoctal escape sequence (issuegh-81548):

Octal escapes in string and bytes literals with value larger than 0o377 now produce DeprecationWarning. In a future Python version they will be a SyntaxWarning and eventually a SyntaxError. (Contributed by Serhiy Storchaka ingh-81548.)

Example:

$ python3.11 -Wdefault -c 'print(list(b"\777"))'<string>:1: DeprecationWarning: invalid octal escape sequence '\777'[255]

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp