##// END OF EJS Templates
Revert 3.7 AST fix...
Matthias Bussonnier -
Show More
@@ -22,7 +22,7 b' script:'
22 22 - cd /tmp && iptest --coverage xml && cd -
23 23 # On the latest Python only, make sure that the docs build.
24 24 - |
25 if [[ "$TRAVIS_PYTHON_VERSION" == "3.6" ]]; then
25 if [[ "$TRAVIS_PYTHON_VERSION" == "3.7" ]]; then
26 26 pip install -r docs/requirements.txt
27 27 python tools/fixup_whats_new_pr.py
28 28 make -C docs/ html SPHINXOPTS="-W"
@@ -35,6 +35,7 b' after_success:'
35 35 matrix:
36 36 include:
37 37 - { python: "3.7", dist: xenial, sudo: true }
38 - { python: "3.7-dev", dist: xenial, sudo: true }
38 39 - { python: "nightly", dist: xenial, sudo: true }
39 40 allow_failures:
40 41 - python: nightly
@@ -92,29 +92,12 b' class CachingCompiler(codeop.Compile):'
92 92 linecache.checkcache = check_linecache_ipython
93 93
94 94
95 def _fix_module_ds(self, module):
96 """
97 Starting in python 3.7 the AST for mule have changed, and if
98 the first expressions encountered is a string it is attached to the
99 `docstring` attribute of the `Module` ast node.
100
101 This breaks IPython, as if this string is the only expression, IPython
102 will not return it as the result of the current cell.
103 """
104 from ast import Str, Expr, Module, fix_missing_locations
105 docstring = getattr(module, 'docstring', None)
106 if not docstring:
107 return module
108 new_body=[Expr(Str(docstring, lineno=1, col_offset=0), lineno=1, col_offset=0)]
109 new_body.extend(module.body)
110 return fix_missing_locations(Module(new_body))
111
112 95 def ast_parse(self, source, filename='<unknown>', symbol='exec'):
113 96 """Parse code to an AST with the current compiler flags active.
114 97
115 98 Arguments are exactly the same as ast.parse (in the standard library),
116 99 and are passed to the built-in compile function."""
117 return self._fix_module_ds(compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1))
100 return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)
118 101
119 102 def reset_compiler_flags(self):
120 103 """Reset compiler flags to default state."""
General Comments 0
You need to be logged in to leave comments. Login now