8000 co-author: nineteendo · python/cpython@ce801c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce801c7

Browse files
committed
co-author: nineteendo
1 parent 904c202 commit ce801c7

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

Lib/_pyrepl/console.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
1717
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1818
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19-
import __future__
2019

2120
from __future__ import annotations
2221

@@ -161,17 +160,6 @@ def __init__(
161160
) -> None:
162161
super().__init__(locals=locals, filename=filename, local_exit=local_exit) # type: ignore[call-arg]
163162
self.can_colorize = _colorize.can_colorize()
164-
self.barry_as_FLUFL = False
165-
166-
def check_barry_as_FLUFL(self, tree):
167-
if self.barry_as_FLUFL:
168-
return
169-
for node in ast.walk(tree):
170-
if isinstance(node, ast.ImportFrom) and node.module == "__future__":
171-
if any(alias.name == "barry_as_FLUFL" for alias in node.names):
172-
self.compile.compiler.flags |= getattr(__future__, "barry_as_FLUFL").compiler_flag
173-
self.barry_as_FLUFL = True
174-
break
175163

176164
def showsyntaxerror(self, filename=None, **kwargs):
177165
super().showsyntaxerror(filename=filename, **kwargs)
@@ -186,8 +174,7 @@ def _excepthook(self, typ, value, tb):
186174

187175
def runsource(self, source, filename="<input>", symbol="single"):
188176
try:
189-
tree = ast.parse(source)
190-
self.check_barry_as_FLUFL(tree)
177+
tree = self.compile.compiler(source, filename, symbol, ast.PyCF_ONLY_AST)
191178
except (SyntaxError, OverflowError, ValueError):
192179
self.showsyntaxerror(filename, source=source)
193180
return False

Lib/codeop.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# Caveat emptor: These flags are undocumented on purpose and depending
4545
# on their effect outside the standard library is **unsupported**.
4646
PyCF_DONT_IMPLY_DEDENT = 0x200
47+
PyCF_ONLY_AST = 0x400
4748
PyCF_ALLOW_INCOMPLETE_INPUT = 0x4000
4849

4950
def _maybe_compile(compiler, source, filename, symbol):
@@ -109,12 +110,14 @@ class Compile:
109110
def __init__(self):
110111
self.flags = PyCF_DONT_IMPLY_DEDENT | PyCF_ALLOW_INCOMPLETE_INPUT
111112

112-
def __call__(self, source, filename, symbol, **kwargs):
113-
flags = self.flags
113+
def __call__(self, source, filename, symbol, flags=0, **kwargs):
114+
flags |= self.flags
114115
if kwargs.get('incomplete_input', True) is False:
115116
flags &= ~PyCF_DONT_IMPLY_DEDENT
116117
flags &= ~PyCF_ALLOW_INCOMPLETE_INPUT
117118
codeob = compile(source, filename, symbol, flags, True)
119+
if flags & PyCF_ONLY_AST:
120+
return compile(source, filename, symbol, flags, True)
118121
for feature in _features:
119122
if codeob.co_flags & feature.compiler_flag:
120123
self.flags |= feature.compiler_flag

0 commit comments

Comments
 (0)
0