From cdf820965ae08b1c5ed047cf9bd575b9ca73e743 2021-11-26 01:51:11 From: Matthias Bussonnier Date: 2021-11-26 01:51:11 Subject: [PATCH] Merge pull request #13327 from Carreau/less-37-II More cleanup of pre-3.8 codepath --- diff --git a/IPython/core/inputtransformer2.py b/IPython/core/inputtransformer2.py index 53e114c..ee70159 100644 --- a/IPython/core/inputtransformer2.py +++ b/IPython/core/inputtransformer2.py @@ -791,9 +791,6 @@ class MaybeAsyncCommandCompiler(CommandCompiler): self.compiler = MaybeAsyncCompile(extra_flags=extra_flags) -if (sys.version_info.major, sys.version_info.minor) >= (3, 8): - _extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT -else: - _extra_flags = ast.PyCF_ONLY_AST +_extra_flags = ast.PyCF_ALLOW_TOP_LEVEL_AWAIT compile_command = MaybeAsyncCommandCompiler(extra_flags=_extra_flags) diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 0f765fe..d74f4c2 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -8,49 +8,44 @@ import ast import bdb import builtins as builtin_mod +import cProfile as profile import gc import itertools +import math import os +import pstats +import re import shlex import sys import time import timeit -import math -import re +from ast import Module +from io import StringIO +from logging import error +from pathlib import Path from pdb import Restart +from warnings import warn -import cProfile as profile -import pstats - -from IPython.core import oinspect -from IPython.core import magic_arguments -from IPython.core import page +from IPython.core import magic_arguments, oinspect, page from IPython.core.error import UsageError from IPython.core.macro import Macro -from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic, - line_cell_magic, on_off, needs_local_scope, - no_var_expand) +from IPython.core.magic import ( + Magics, + cell_magic, + line_cell_magic, + line_magic, + magics_class, + needs_local_scope, + no_var_expand, + on_off, +) from IPython.testing.skipdoctest import skip_doctest -from IPython.utils.contexts import preserve_keys from IPython.utils.capture import capture_output +from IPython.utils.contexts import preserve_keys from IPython.utils.ipstruct import Struct from IPython.utils.module_paths import find_mod from IPython.utils.path import get_py_filename, shellglob from IPython.utils.timing import clock, clock2 -from warnings import warn -from logging import error -from pathlib import Path -from io import StringIO -from pathlib import Path - -if sys.version_info > (3,8): - from ast import Module -else : - # mock the new API, ignore second argument - # see https://github.com/ipython/ipython/issues/11590 - from ast import Module as OriginalModule - Module = lambda nodelist, type_ignores: OriginalModule(nodelist) - #----------------------------------------------------------------------------- # Magic implementation classes diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index a72eb68..fdd6d90 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -1308,12 +1308,7 @@ def test_time_no_var_expand(): # this is slow, put at the end for local testing. def test_timeit_arguments(): "Test valid timeit arguments, should not cause SyntaxError (GH #1269)" - if sys.version_info < (3,7): - _ip.magic("timeit -n1 -r1 ('#')") - else: - # 3.7 optimize no-op statement like above out, and complain there is - # nothing in the for loop. - _ip.magic("timeit -n1 -r1 a=('#')") + _ip.magic("timeit -n1 -r1 a=('#')") TEST_MODULE = """