gh-102567: Add -X importtime=2 for logging an importtime message for already-loaded modules (#118655)

Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
Noah Kim 2025-05-05 20:03:55 -04:00 committed by GitHub
parent e6f8e0a035
commit c4bcc6a778
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 166 additions and 44 deletions

View file

@ -24,6 +24,7 @@
import sys
import ctypes
import types
from ctypes.wintypes import (
_COORD,
WORD,
@ -58,6 +59,12 @@ def __init__(self, err: int | None, descr: str | None = None) -> None:
self.err = err
self.descr = descr
# declare nt optional to allow None assignment on other platforms
nt: types.ModuleType | None
try:
import nt
except ImportError:
nt = None
TYPE_CHECKING = False
@ -121,9 +128,8 @@ class _error(Exception):
def _supports_vt():
try:
import nt
return nt._supports_virtual_terminal()
except (ImportError, AttributeError):
except AttributeError:
return False
class WindowsConsole(Console):
@ -235,11 +241,9 @@ def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None:
@property
def input_hook(self):
try:
import nt
except ImportError:
return None
if nt._is_inputhook_installed():
# avoid inline imports here so the repl doesn't get flooded
# with import logging from -X importtime=2
if nt is not None and nt._is_inputhook_installed():
return nt._inputhook
def __write_changed_line(