diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2021-02-13 06:49:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-13 06:49:18 (GMT) |
commit | b676f5f809007533db3e3fdd01243959dd233d57 (patch) | |
tree | cab1bce2a3217005a8fa84016747d5c1eee4444d /Lib | |
parent | 762fe7deed34a1d5294bf82071d318c8427b4893 (diff) | |
download | cpython-b676f5f809007533db3e3fdd01243959dd233d57.zip cpython-b676f5f809007533db3e3fdd01243959dd233d57.tar.gz cpython-b676f5f809007533db3e3fdd01243959dd233d57.tar.bz2 |
bpo-43202: More codeop._maybe_compile clean-ups (GH-24512)
Add comment, end others with period, remove unused variables,
initialize others only when needed, and add explicit return.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/codeop.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/codeop.py b/Lib/codeop.py index b3af93f..6b56be4 100644 --- a/Lib/codeop.py +++ b/Lib/codeop.py @@ -64,24 +64,21 @@ _features = [getattr(__future__, fname) __all__ = ["compile_command", "Compile", "CommandCompiler"] -PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h +PyCF_DONT_IMPLY_DEDENT = 0x200 # Matches pythonrun.h. def _maybe_compile(compiler, source, filename, symbol): - # Check for source consisting of only blank lines and comments + # 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 + break # Leave it alone. else: if symbol != "eval": source = "pass" # Replace it with a 'pass' statement - err = err1 = err2 = None - code1 = code2 = None - try: return compiler(source, filename, symbol) - except SyntaxError: + except SyntaxError: # Let other compile() errors propagate. pass # Catch syntax warnings after the first compile @@ -89,6 +86,7 @@ def _maybe_compile(compiler, source, filename, symbol): with warnings.catch_warnings(): warnings.simplefilter("error") + code1 = err1 = err2 = None try: code1 = compiler(source + "\n", filename, symbol) except SyntaxError as e: @@ -102,6 +100,8 @@ def _maybe_compile(compiler, source, filename, symbol): try: if not code1 and _is_syntax_error(err1, err2): raise err1 + else: + return None finally: err1 = err2 = None |