mirror of
https://github.com/python/cpython.git
synced 2025-10-24 02:13:49 +00:00
[3.13] gh-134109: Fix showing comments in pydoc output for argparse (GH-134110) (GH-134113)
Comments immediately preceding the object's source code are used
if the object has no docstring.
Comments that do not describe the object should be separated from
the following source code by an empty line.
(cherry picked from commit 71cf4dd622)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4291bbe88b
commit
510e28ec29
1 changed files with 13 additions and 0 deletions
|
|
@ -190,6 +190,7 @@ def __init__(self,
|
|||
# ===============================
|
||||
# Section and indentation methods
|
||||
# ===============================
|
||||
|
||||
def _indent(self):
|
||||
self._current_indent += self._indent_increment
|
||||
self._level += 1
|
||||
|
|
@ -237,6 +238,7 @@ def _add_item(self, func, args):
|
|||
# ========================
|
||||
# Message building methods
|
||||
# ========================
|
||||
|
||||
def start_section(self, heading):
|
||||
self._indent()
|
||||
section = self._Section(self, self._current_section, heading)
|
||||
|
|
@ -280,6 +282,7 @@ def add_arguments(self, actions):
|
|||
# =======================
|
||||
# Help-formatting methods
|
||||
# =======================
|
||||
|
||||
def format_help(self):
|
||||
help = self._root_section.format_help()
|
||||
if help:
|
||||
|
|
@ -1402,6 +1405,7 @@ def __init__(self,
|
|||
# ====================
|
||||
# Registration methods
|
||||
# ====================
|
||||
|
||||
def register(self, registry_name, value, object):
|
||||
registry = self._registries.setdefault(registry_name, {})
|
||||
registry[value] = object
|
||||
|
|
@ -1412,6 +1416,7 @@ def _registry_get(self, registry_name, value, default=None):
|
|||
# ==================================
|
||||
# Namespace default accessor methods
|
||||
# ==================================
|
||||
|
||||
def set_defaults(self, **kwargs):
|
||||
self._defaults.update(kwargs)
|
||||
|
||||
|
|
@ -1431,6 +1436,7 @@ def get_default(self, dest):
|
|||
# =======================
|
||||
# Adding argument actions
|
||||
# =======================
|
||||
|
||||
def add_argument(self, *args, **kwargs):
|
||||
"""
|
||||
add_argument(dest, ..., name=value, ...)
|
||||
|
|
@ -1820,6 +1826,7 @@ def identity(string):
|
|||
# =======================
|
||||
# Pretty __repr__ methods
|
||||
# =======================
|
||||
|
||||
def _get_kwargs(self):
|
||||
names = [
|
||||
'prog',
|
||||
|
|
@ -1834,6 +1841,7 @@ def _get_kwargs(self):
|
|||
# ==================================
|
||||
# Optional/Positional adding methods
|
||||
# ==================================
|
||||
|
||||
def add_subparsers(self, **kwargs):
|
||||
if self._subparsers is not None:
|
||||
raise ArgumentError(None, _('cannot have multiple subparser arguments'))
|
||||
|
|
@ -1885,6 +1893,7 @@ def _get_positional_actions(self):
|
|||
# =====================================
|
||||
# Command line argument parsing methods
|
||||
# =====================================
|
||||
|
||||
def parse_args(self, args=None, namespace=None):
|
||||
args, argv = self.parse_known_args(args, namespace)
|
||||
if argv:
|
||||
|
|
@ -2479,6 +2488,7 @@ def parse_known_intermixed_args(self, args=None, namespace=None):
|
|||
# ========================
|
||||
# Value conversion methods
|
||||
# ========================
|
||||
|
||||
def _get_values(self, action, arg_strings):
|
||||
# optional argument produces a default when not present
|
||||
if not arg_strings and action.nargs == OPTIONAL:
|
||||
|
|
@ -2570,6 +2580,7 @@ def _check_value(self, action, value):
|
|||
# =======================
|
||||
# Help-formatting methods
|
||||
# =======================
|
||||
|
||||
def format_usage(self):
|
||||
formatter = self._get_formatter()
|
||||
formatter.add_usage(self.usage, self._actions,
|
||||
|
|
@ -2605,6 +2616,7 @@ def _get_formatter(self):
|
|||
# =====================
|
||||
# Help-printing methods
|
||||
# =====================
|
||||
|
||||
def print_usage(self, file=None):
|
||||
if file is None:
|
||||
file = _sys.stdout
|
||||
|
|
@ -2626,6 +2638,7 @@ def _print_message(self, message, file=None):
|
|||
# ===============
|
||||
# Exiting methods
|
||||
# ===============
|
||||
|
||||
def exit(self, status=0, message=None):
|
||||
if message:
|
||||
self._print_message(message, _sys.stderr)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue