mirror of
https://github.com/python/cpython.git
synced 2025-11-03 07:01:21 +00:00
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:
parent
e6f8e0a035
commit
c4bcc6a778
15 changed files with 166 additions and 44 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue