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

Trailing backslash in raw string format causes EOL #72134

Closed
cfgbd mannequin opened this issue Sep 3, 2016 · 3 comments
Closed

Trailing backslash in raw string format causes EOL #72134

cfgbd mannequin opened this issue Sep 3, 2016 · 3 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@cfgbd
Copy link
Mannequin

cfgbd mannequin commented Sep 3, 2016

BPO 27947
Nosy @ammaraskar

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-09-03.03:05:31.355>
created_at = <Date 2016-09-03.02:47:54.846>
labels = ['type-bug', 'invalid']
title = 'Trailing backslash in raw string format causes EOL'
updated_at = <Date 2016-09-03.03:12:11.477>
user = 'https://bugs.python.org/cfgbd'

bugs.python.org fields:

activity = <Date 2016-09-03.03:12:11.477>
actor = 'cfgbd'
assignee = 'none'
closed = True
closed_date = <Date 2016-09-03.03:05:31.355>
closer = 'tim.peters'
components = []
creation = <Date 2016-09-03.02:47:54.846>
creator = 'cfgbd'
dependencies = []
files = []
hgrepos = []
issue_num = 27947
keywords = []
message_count = 3.0
messages = ['274282', '274283', '274284']
nosy_count = 2.0
nosy_names = ['ammar2', 'cfgbd']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27947'
versions = ['Python 3.2']

@cfgbd
Copy link
Mannequin Author

cfgbd mannequin commented Sep 3, 2016

In python shell, I typed words and got result as follows. It seems that the use of 'r' before a literal string may cause an error that the an odd '\' at the end of literal string blocked the quote.

>>> rb'abc\\\'
SyntaxError: EOL while scanning string literal
>>> rb'abc\\'
b'abc\\\\'
>>> br'abc\\\ '
b'abc\\\\\\ '
>>> br'abc\\\'
SyntaxError: EOL while scanning string literal
>>> r'\\'
'\\\\'
>>> r'\\\'
SyntaxError: EOL while scanning string literal

@cfgbd cfgbd mannequin added the type-bug An unexpected behavior, bug, or error label Sep 3, 2016
@ammaraskar
Copy link
Member

This isn't a bug, in fact this very behavior is documented within the string docs, please read the last paragraph here:

https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals

@ammaraskar ammaraskar changed the title Bug of python interpreter Trailing backslash in raw string format causes EOL Sep 3, 2016
@tim-one tim-one closed this as completed Sep 3, 2016
@tim-one tim-one added the invalid label Sep 3, 2016
@cfgbd
Copy link
Mannequin Author

cfgbd mannequin commented Sep 3, 2016

Thanks for comment. Here I got my answer from string docs.

Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; for example, r"\"" is a valid string literal consisting of two characters: a backslash and a double quote; r"\" is not a valid string literal (even a raw string cannot end in an odd number of backslashes). Specifically, a raw literal cannot end in a single backslash (since the backslash would escape the following quote character). Note also that a single backslash followed by a newline is interpreted as those two characters as part of the literal, not as a line continuation.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants