diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index d50ec34e54d710..70dd342ab66a47 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -645,6 +645,27 @@ are set. .. versionadded:: 3.14 +To highlight inline code in your description or epilog text, you can use +backticks:: + + >>> parser = argparse.ArgumentParser( + ... formatter_class=argparse.RawDescriptionHelpFormatter, + ... epilog='''Examples: + ... `python -m myapp --verbose` + ... `python -m myapp --config settings.json` + ... ''') + +When colors are enabled, the text inside backticks will be displayed in a +distinct color to help examples stand out. When colors are disabled, backticks +are preserved as-is, which is readable in plain text. + +.. note:: + + Backtick markup only applies to description and epilog text. It does not + apply to individual argument ``help`` strings. + +.. versionadded:: 3.15 + The add_argument() method ------------------------- diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst index c5ea78c1683761..08cb1770d7a22e 100644 --- a/Doc/library/importlib.rst +++ b/Doc/library/importlib.rst @@ -210,6 +210,12 @@ Functions :exc:`ModuleNotFoundError` is raised when the module being reloaded lacks a :class:`~importlib.machinery.ModuleSpec`. + .. versionchanged:: next + If *module* is a lazy module that has not yet been materialized (i.e., + loaded via :class:`importlib.util.LazyLoader` and not yet accessed), + calling :func:`reload` is a no-op and returns the module unchanged. + This prevents the reload from unintentionally triggering the lazy load. + .. warning:: This function is not thread-safe. Calling it from multiple threads can result in unexpected behavior. It's recommended to use the :class:`threading.Lock` diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 58f3a8ecd7c2e0..4e9946fd4567cd 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -2869,8 +2869,8 @@ ABCs and Protocols for working with I/O --------------------------------------- .. class:: IO[AnyStr] - TextIO[AnyStr] - BinaryIO[AnyStr] + TextIO + BinaryIO Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])`` and ``BinaryIO(IO[bytes])`` diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 1d8b838cd2e7f0..afefcc15ab2d55 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -423,6 +423,10 @@ argparse default to ``True``. This enables suggestions for mistyped arguments by default. (Contributed by Jakob Schluse in :gh:`140450`.) +* Added backtick markup support in description and epilog text to highlight + inline code when color output is enabled. + (Contributed by Savannah Ostrowski in :gh:`142390`.) + calendar -------- diff --git a/Lib/argparse.py b/Lib/argparse.py index ee7ebc4696a0f7..633fec69ea4615 100644 --- a/Lib/argparse.py +++ b/Lib/argparse.py @@ -517,7 +517,27 @@ def _format_text(self, text): text = text % dict(prog=self._prog) text_width = max(self._width - self._current_indent, 11) indent = ' ' * self._current_indent - return self._fill_text(text, text_width, indent) + '\n\n' + text = self._fill_text(text, text_width, indent) + text = self._apply_text_markup(text) + return text + '\n\n' + + def _apply_text_markup(self, text): + """Apply color markup to text. + + Supported markup: + `...` - inline code (rendered with prog_extra color) + + When colors are disabled, backticks are preserved as-is. + """ + t = self._theme + if not t.reset: + return text + text = _re.sub( + r'`([^`]+)`', + rf'{t.prog_extra}\1{t.reset}', + text, + ) + return text def _format_action(self, action): # determine the required width and the entry label diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py index a7d57561ead046..694fea806f7944 100644 --- a/Lib/importlib/__init__.py +++ b/Lib/importlib/__init__.py @@ -97,6 +97,11 @@ def reload(module): The module must have been successfully imported before. """ + # If a LazyModule has not yet been materialized, reload is a no-op. + if importlib_util := sys.modules.get('importlib.util'): + if lazy_module_type := getattr(importlib_util, '_LazyModule', None): + if isinstance(module, lazy_module_type): + return module try: name = module.__spec__.name except AttributeError: diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.css b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.css index 2940f263f7ff29..03eb2274d23e68 100644 --- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.css +++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.css @@ -275,16 +275,8 @@ body.resizing-sidebar { } /* View Mode Section */ -.view-mode-section { - padding-bottom: 20px; - border-bottom: 1px solid var(--border); -} - -.view-mode-section .section-title { - margin-bottom: 12px; -} - -.view-mode-section .toggle-switch { +.view-mode-section .section-content { + display: flex; justify-content: center; } @@ -316,7 +308,7 @@ body.resizing-sidebar { } .section-content { - transition: max-height var(--transition-normal), opacity var(--transition-normal); + transition: max-height var(--transition-slow) ease-out, opacity var(--transition-normal) ease-out, padding var(--transition-normal) ease-out; max-height: 1000px; opacity: 1; } @@ -324,7 +316,9 @@ body.resizing-sidebar { .collapsible.collapsed .section-content { max-height: 0; opacity: 0; - margin-bottom: -10px; + padding-top: 0; + pointer-events: none; + transition: max-height var(--transition-slow) ease-in, opacity var(--transition-normal) ease-in, padding var(--transition-normal) ease-in; } /* -------------------------------------------------------------------------- @@ -634,10 +628,6 @@ body.resizing-sidebar { Legend -------------------------------------------------------------------------- */ -.legend-section { - margin-top: auto; - padding-top: 12px; -} .legend { display: flex; @@ -1023,3 +1013,7 @@ body.resizing-sidebar { border-color: #8e44ad; box-shadow: 0 0 8px rgba(142, 68, 173, 0.3); } + +.toggle-switch:focus-visible { + border-radius: 4px; +} diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js index 6345320bd2555d..17fd95af859587 100644 --- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js +++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph.js @@ -1302,6 +1302,17 @@ function initFlamegraph() { } } +// Keyboard shortcut: Enter/Space activates toggle switches +document.addEventListener('keydown', function(e) { + if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') { + return; + } + if ((e.key === 'Enter' || e.key === ' ') && e.target.classList.contains('toggle-switch')) { + e.preventDefault(); + e.target.click(); + } +}); + if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", initFlamegraph); } else { diff --git a/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html b/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html index 02855563f83f7c..936c9adfc8c519 100644 --- a/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html +++ b/Lib/profiling/sampling/_flamegraph_assets/flamegraph_template.html @@ -102,12 +102,19 @@ -