[issue45811] Improve error message when source code contains invisible control characters

2021-11-20 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-20 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 81f4e116ef7d30ef6e2041c2d6cf29af511a3a02 by Pablo Galindo Salgado 
in branch 'main':
bpo-45811: Improve error message when source code contains invisible control 
characters (GH-29654)
https://github.com/python/cpython/commit/81f4e116ef7d30ef6e2041c2d6cf29af511a3a02


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-19 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch
pull_requests: +27896
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/29654

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-19 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

I agree.

--
nosy: +terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-19 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-15 Thread Andre Roberge


Change by Andre Roberge :


--
nosy: +aroberge

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45811] Improve error message when source code contains invisible control characters

2021-11-15 Thread Steven D'Aprano


New submission from Steven D'Aprano :

Invisible control characters (aside from white space) are not permitted in 
source code, but the syntax error we get is confusing and lacks information:

>>> s = 'print\x17("Hello")'
>>> eval(s)
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1
print("Hello")
 ^
SyntaxError: invalid syntax


The caret points to an invisible character. The offending control character is 
not visible in the traceback, or the source code unless you use a hex editor. 
Copying and pasting the string from the traceback, or the source code, may 
remove the control character (depending on the tools you use), making it even 
harder to track down the problem.

I suggest that the syntax error should state that the problem is an invisible 
control character, and display it as a standard human-readable code together 
with its hex code:

SyntaxError: invisible control character ^W (0x17)


Just in case it isn't obvious what the mapping between controls and the human 
visible string is:

def control(char):
n = ord(char)
if 0 <= n <= 0x1F:
# C0 control codes
return '^' + chr(ord('@')+n)
elif n == 0x7F:
# DEL
return '^?'
elif 0x80 <= n <= 0x9F:
# C1 control codes
return 'Esc+' + chr(ord('@')+n-0x80)
else:
raise ValueError('Not a control character.')


https://en.wikipedia.org/wiki/C0_and_C1_control_codes

--
components: Interpreter Core
messages: 406379
nosy: steven.daprano
priority: normal
severity: normal
status: open
title: Improve error message when source code contains invisible control 
characters
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com