Skip to content

Commit 61f309b

Browse files
committed
improve comments
1 parent 7f16b4b commit 61f309b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/_pyrepl/console.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,15 @@ def runsource(self, source, filename="<input>", symbol="single"):
214214
self.showsyntaxerror(filename, source=source)
215215
return False
216216

217-
# validate stuff that cannot be validated with AST parsing only
218-
flags = self.compile.compiler.flags
217+
# Validate stuff that cannot be validated with AST parsing only,
218+
# such as assigning to a variable before a global declaration,
219+
#
220+
# While runsource("x = 1; global x") would fail, runsource("x = 1")
221+
# followed by runsource("global x") would still work since preventing
222+
# this requires the REPL to remember the global names whose number
223+
# grows faster than in a regular program, which then becomes less
224+
# efficient or relevant for the user.
225+
flags = self.compile.compiler.flags # may contain active futures
219226
flags &= ~codeop.PyCF_DONT_IMPLY_DEDENT
220227
flags &= ~codeop.PyCF_ALLOW_INCOMPLETE_INPUT
221228
try:

0 commit comments

Comments
 (0)