Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-131927: Prevent emitting optimizer warnings twice in the REPL#131993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
iritkatriel merged 12 commits intopython:mainfromtomasr8:repl-warnings
Apr 12, 2025
Merged
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Revert REPL changes
  • Loading branch information
@tomasr8
tomasr8 committedApr 5, 2025
commit742a4b1b8852ffafa4b52bd5f621741465b9bba4
43 changes: 8 additions & 35 deletionsLib/_pyrepl/console.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -28,7 +28,6 @@
from dataclasses import dataclass, field
import os.path
import sys
import warnings


TYPE_CHECKING = False
Expand DownExpand Up@@ -189,29 +188,24 @@ def runcode(self, code):

def runsource(self, source, filename="<input>", symbol="single"):
try:
with warnings.catch_warnings(record=True) as all_warnings:
warnings.simplefilter("always")
tree = self.compile.compiler(
source,
filename,
"exec",
ast.PyCF_ONLY_AST,
incomplete_input=False,
)
tree = self.compile.compiler(
source,
filename,
"exec",
ast.PyCF_ONLY_AST,
incomplete_input=False,
)
except (SyntaxError, OverflowError, ValueError):
self.showsyntaxerror(filename, source=source)
return False
_replay_warnings(all_warnings)
if tree.body:
*_, last_stmt = tree.body
for stmt in tree.body:
wrapper = ast.Interactive if stmt is last_stmt else ast.Module
the_symbol = symbol if stmt is last_stmt else "exec"
item = wrapper([stmt])
try:
with warnings.catch_warnings(record=True) as stmt_warnings:
warnings.simplefilter("always")
code = self.compile.compiler(item, filename, the_symbol)
code = self.compile.compiler(item, filename, the_symbol)
linecache._register_code(code, source, filename)
except SyntaxError as e:
if e.args[0] == "'await' outside function":
Expand All@@ -226,31 +220,10 @@ def runsource(self, source, filename="<input>", symbol="single"):
self.showsyntaxerror(filename, source=source)
return False

# Only emit new warnings and throw away those
# which were already emitted when the source
# was compiled to AST.
# This prevents emitting duplicate warnings which are
# raised in the AST optimizer.
all_warnings = {str(w) for w in all_warnings}
new_warnings = [w for w in stmt_warnings
if str(w) not in all_warnings]
_replay_warnings(new_warnings)

if code is None:
return True

result = self.runcode(code)
if result is self.STATEMENT_FAILED:
break
return False


def _replay_warnings(ws):
for w in ws:
warnings.warn_explicit(
message=w.message,
category=w.category,
filename=w.filename,
lineno=w.lineno,
source=w.source,
)

[8]ページ先頭

©2009-2025 Movatter.jp