Terry J. Reedy <tjre...@udel.edu> added the comment:

_maybe_compile currently compiles the possibly complete statement up to 3 times 
-- with C-coded compile.  Without doing any timing tests, I wondered if 3 times 
is really necessary.  Nick suggested that using the tokenize module to 
determine the number of hanging indents, combined with some yet to be 
determined logic, might be an alternative.  But since tokenize is written in 
Python, the result might not be any faster.

Checking the error message aims at specifically fixing this issue.  But I am 
not sure if the check is sufficient or if more logic is needed.
  "def a():\n   nonlocal c\n" should ideally raise.
  "def a():\n   def b():\n    nonlocal c\n" must not.

At least the second should be used for a new test.

I would start by adding debug prints to see the result of each compile and then 
testing with those two lines.

----------
type:  -> behavior
versions: +Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue19335>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to