[3.13] gh-120678: pyrepl: Include globals from modules passed with -i (GH-120904) (#121916)

(cherry picked from commit ac07451116)

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Miss Islington (bot) 2024-07-17 16:52:46 +02:00 committed by GitHub
parent 5a8e1373fe
commit 3d9692dbf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 178 additions and 11 deletions

View file

@ -1,3 +1,4 @@
import os
from code import InteractiveConsole
from functools import partial
from typing import Iterable
@ -100,8 +101,18 @@ def handle_all_events(
)
def make_clean_env() -> dict[str, str]:
clean_env = os.environ.copy()
for k in clean_env.copy():
if k.startswith("PYTHON"):
clean_env.pop(k)
clean_env.pop("FORCE_COLOR", None)
clean_env.pop("NO_COLOR", None)
return clean_env
class FakeConsole(Console):
def __init__(self, events, encoding="utf-8"):
def __init__(self, events, encoding="utf-8") -> None:
self.events = iter(events)
self.encoding = encoding
self.screen = []