From bebb86e9358dd01bfee47832dbfaea87bd039ef2 2018-09-12 10:37:56 From: Matthias Bussonnier Date: 2018-09-12 10:37:56 Subject: [PATCH] Revert 3.7 AST fix Also start testing on 3.7-dev and build docs on 3.7 --- diff --git a/.travis.yml b/.travis.yml index 5b0281f..09e1614 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ script: - cd /tmp && iptest --coverage xml && cd - # On the latest Python only, make sure that the docs build. - | - if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then + if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]]; then pip install -r docs/requirements.txt python tools/fixup_whats_new_pr.py make -C docs/ html SPHINXOPTS="-W" @@ -35,6 +35,7 @@ after_success: matrix: include: - { python: "3.7", dist: xenial, sudo: true } + - { python: "3.7-dev", dist: xenial, sudo: true } - { python: "nightly", dist: xenial, sudo: true } allow_failures: - python: nightly diff --git a/IPython/core/compilerop.py b/IPython/core/compilerop.py index c5abd06..6a055f9 100644 --- a/IPython/core/compilerop.py +++ b/IPython/core/compilerop.py @@ -92,30 +92,13 @@ class CachingCompiler(codeop.Compile): linecache.checkcache = check_linecache_ipython - def _fix_module_ds(self, module): - """ - Starting in python 3.7 the AST for mule have changed, and if - the first expressions encountered is a string it is attached to the - `docstring` attribute of the `Module` ast node. - - This breaks IPython, as if this string is the only expression, IPython - will not return it as the result of the current cell. - """ - from ast import Str, Expr, Module, fix_missing_locations - docstring = getattr(module, 'docstring', None) - if not docstring: - return module - new_body=[Expr(Str(docstring, lineno=1, col_offset=0), lineno=1, col_offset=0)] - new_body.extend(module.body) - return fix_missing_locations(Module(new_body)) - def ast_parse(self, source, filename='', symbol='exec'): """Parse code to an AST with the current compiler flags active. Arguments are exactly the same as ast.parse (in the standard library), and are passed to the built-in compile function.""" - return self._fix_module_ds(compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)) - + return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1) + def reset_compiler_flags(self): """Reset compiler flags to default state.""" # This value is copied from codeop.Compile.__init__, so if that ever