Lewis Ball <lrjb...@gmail.com> added the comment:
Okay, on further examination `find_good_parse_start` first looks for a line ending with ':\n', and then looks to match _synchre on that line. If it can't find any line ending in ':\n' then it will just look for the first occurrence of something in _synchre to truncate on. If it can't find anything at that point, it just doesn't truncate and the whole code is checked for a bracket match. So the reason that ``` else ( else) ``` works is because there is no `:` after the first else, and adding `:` will cause the matching to fail. This seems reasonable, and I was probably too quick to say that the function goes back further than it needs to when looking to truncate. It seems like then that `else` being removed from _synchre will fix this, and mean that the only time brackets aren't matched are when invalid code is typed, something like: ``` ( def) ``` I can put in a PR for this tomorrow (probably removing `yield` at the same time) if this sounds like the right fix. P.S. Here is an example of the similar `yield` error that Terry alluded to: ``` def f(): for i in range(10): ( yield x) ``` ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41388> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com