mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
gh-134109: Fix showing comments in pydoc output for argparse (GH-134110)
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.
This commit is contained in:
parent
ea2d707bd5
commit
71cf4dd622
1 changed files with 13 additions and 0 deletions
|
@ -205,6 +205,7 @@ class HelpFormatter(object):
|
||||||
# ===============================
|
# ===============================
|
||||||
# Section and indentation methods
|
# Section and indentation methods
|
||||||
# ===============================
|
# ===============================
|
||||||
|
|
||||||
def _indent(self):
|
def _indent(self):
|
||||||
self._current_indent += self._indent_increment
|
self._current_indent += self._indent_increment
|
||||||
self._level += 1
|
self._level += 1
|
||||||
|
@ -256,6 +257,7 @@ class HelpFormatter(object):
|
||||||
# ========================
|
# ========================
|
||||||
# Message building methods
|
# Message building methods
|
||||||
# ========================
|
# ========================
|
||||||
|
|
||||||
def start_section(self, heading):
|
def start_section(self, heading):
|
||||||
self._indent()
|
self._indent()
|
||||||
section = self._Section(self, self._current_section, heading)
|
section = self._Section(self, self._current_section, heading)
|
||||||
|
@ -299,6 +301,7 @@ class HelpFormatter(object):
|
||||||
# =======================
|
# =======================
|
||||||
# Help-formatting methods
|
# Help-formatting methods
|
||||||
# =======================
|
# =======================
|
||||||
|
|
||||||
def format_help(self):
|
def format_help(self):
|
||||||
help = self._root_section.format_help()
|
help = self._root_section.format_help()
|
||||||
if help:
|
if help:
|
||||||
|
@ -1467,6 +1470,7 @@ class _ActionsContainer(object):
|
||||||
# ====================
|
# ====================
|
||||||
# Registration methods
|
# Registration methods
|
||||||
# ====================
|
# ====================
|
||||||
|
|
||||||
def register(self, registry_name, value, object):
|
def register(self, registry_name, value, object):
|
||||||
registry = self._registries.setdefault(registry_name, {})
|
registry = self._registries.setdefault(registry_name, {})
|
||||||
registry[value] = object
|
registry[value] = object
|
||||||
|
@ -1477,6 +1481,7 @@ class _ActionsContainer(object):
|
||||||
# ==================================
|
# ==================================
|
||||||
# Namespace default accessor methods
|
# Namespace default accessor methods
|
||||||
# ==================================
|
# ==================================
|
||||||
|
|
||||||
def set_defaults(self, **kwargs):
|
def set_defaults(self, **kwargs):
|
||||||
self._defaults.update(kwargs)
|
self._defaults.update(kwargs)
|
||||||
|
|
||||||
|
@ -1496,6 +1501,7 @@ class _ActionsContainer(object):
|
||||||
# =======================
|
# =======================
|
||||||
# Adding argument actions
|
# Adding argument actions
|
||||||
# =======================
|
# =======================
|
||||||
|
|
||||||
def add_argument(self, *args, **kwargs):
|
def add_argument(self, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
add_argument(dest, ..., name=value, ...)
|
add_argument(dest, ..., name=value, ...)
|
||||||
|
@ -1921,6 +1927,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# =======================
|
# =======================
|
||||||
# Pretty __repr__ methods
|
# Pretty __repr__ methods
|
||||||
# =======================
|
# =======================
|
||||||
|
|
||||||
def _get_kwargs(self):
|
def _get_kwargs(self):
|
||||||
names = [
|
names = [
|
||||||
'prog',
|
'prog',
|
||||||
|
@ -1935,6 +1942,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# ==================================
|
# ==================================
|
||||||
# Optional/Positional adding methods
|
# Optional/Positional adding methods
|
||||||
# ==================================
|
# ==================================
|
||||||
|
|
||||||
def add_subparsers(self, **kwargs):
|
def add_subparsers(self, **kwargs):
|
||||||
if self._subparsers is not None:
|
if self._subparsers is not None:
|
||||||
raise ValueError('cannot have multiple subparser arguments')
|
raise ValueError('cannot have multiple subparser arguments')
|
||||||
|
@ -1988,6 +1996,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# =====================================
|
# =====================================
|
||||||
# Command line argument parsing methods
|
# Command line argument parsing methods
|
||||||
# =====================================
|
# =====================================
|
||||||
|
|
||||||
def parse_args(self, args=None, namespace=None):
|
def parse_args(self, args=None, namespace=None):
|
||||||
args, argv = self.parse_known_args(args, namespace)
|
args, argv = self.parse_known_args(args, namespace)
|
||||||
if argv:
|
if argv:
|
||||||
|
@ -2582,6 +2591,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# ========================
|
# ========================
|
||||||
# Value conversion methods
|
# Value conversion methods
|
||||||
# ========================
|
# ========================
|
||||||
|
|
||||||
def _get_values(self, action, arg_strings):
|
def _get_values(self, action, arg_strings):
|
||||||
# optional argument produces a default when not present
|
# optional argument produces a default when not present
|
||||||
if not arg_strings and action.nargs == OPTIONAL:
|
if not arg_strings and action.nargs == OPTIONAL:
|
||||||
|
@ -2681,6 +2691,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# =======================
|
# =======================
|
||||||
# Help-formatting methods
|
# Help-formatting methods
|
||||||
# =======================
|
# =======================
|
||||||
|
|
||||||
def format_usage(self):
|
def format_usage(self):
|
||||||
formatter = self._get_formatter()
|
formatter = self._get_formatter()
|
||||||
formatter.add_usage(self.usage, self._actions,
|
formatter.add_usage(self.usage, self._actions,
|
||||||
|
@ -2718,6 +2729,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# =====================
|
# =====================
|
||||||
# Help-printing methods
|
# Help-printing methods
|
||||||
# =====================
|
# =====================
|
||||||
|
|
||||||
def print_usage(self, file=None):
|
def print_usage(self, file=None):
|
||||||
if file is None:
|
if file is None:
|
||||||
file = _sys.stdout
|
file = _sys.stdout
|
||||||
|
@ -2739,6 +2751,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||||
# ===============
|
# ===============
|
||||||
# Exiting methods
|
# Exiting methods
|
||||||
# ===============
|
# ===============
|
||||||
|
|
||||||
def exit(self, status=0, message=None):
|
def exit(self, status=0, message=None):
|
||||||
if message:
|
if message:
|
||||||
self._print_message(message, _sys.stderr)
|
self._print_message(message, _sys.stderr)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue