Author cheryl.sabella
Recipients cheryl.sabella, miss-islington, rhettinger, serhiy.storchaka, taleinat, terry.reedy
Date 2020-05-25.22:41:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1590446506.6.0.661192476693.issue37824@roundup.psfhosted.org>
In-reply-to
Content
Terry,

I put this into debug and found the reason it's printing the warning three times.  In `codeop.py`, it's running `_maybe_compile` and there are three try statements:

```
def _maybe_compile(compiler, source, filename, symbol):
    # Check for source consisting of only blank lines and comments
    for line in source.split("\n"):
        line = line.strip()
        if line and line[0] != '#':
            break               # Leave it alone
    else:
        if symbol != "eval":
            source = "pass"     # Replace it with a 'pass' statement

    err = err1 = err2 = None
    code = code1 = code2 = None

    try:
        code = compiler(source, filename, symbol)
    except SyntaxError:
        pass

    try:
        code1 = compiler(source + "\n", filename, symbol)
    except SyntaxError as e:
        err1 = e

    try:
        code2 = compiler(source + "\n\n", filename, symbol)
    except SyntaxError as e:
        err2 = e

    try:
        if code:
            return code
        if not code1 and repr(err1) == repr(err2):
            raise err1
    finally:
        err1 = err2 = None
```

It also has this in the module docstring:
```
Compile three times: as is, with \n, and with \n\n appended.  If it
compiles as is, it's complete.  If it compiles with one \n appended,
we expect more.  If it doesn't compile either way, we compare the
error we get when compiling with \n or \n\n appended.  If the errors
are the same, the code is broken.  But if the errors are different, we
expect more.  Not intuitive; not even guaranteed to hold in future
releases; but this matches the compiler's behavior from Python 1.4
through 2.2, at least.
```
History
Date User Action Args
2020-05-25 22:41:46cheryl.sabellasetrecipients: + cheryl.sabella, rhettinger, terry.reedy, taleinat, serhiy.storchaka, miss-islington
2020-05-25 22:41:46cheryl.sabellasetmessageid: <1590446506.6.0.661192476693.issue37824@roundup.psfhosted.org>
2020-05-25 22:41:46cheryl.sabellalinkissue37824 messages
2020-05-25 22:41:46cheryl.sabellacreate