gh-120678: pyrepl: Include globals from modules passed with -i (GH-120904)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
This commit is contained in:
Alex Waygood 2024-07-17 15:18:42 +01:00 committed by GitHub
parent 58753f33e4
commit ac07451116
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 @@ handle_events_narrow_console = partial(
)
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 = []