Skip to content

Commit

Permalink
pythongh-100520: Fix rst markup in configparser docstrings (pytho…
Browse files Browse the repository at this point in the history
…nGH-100524)

(cherry picked from commit 199507b)

Co-authored-by: Nikita Sobolev <[email protected]>
  • Loading branch information
sobolevn authored and miss-islington committed Dec 26, 2022
1 parent a167365 commit ed21112
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,37 @@
inline_comment_prefixes=None, strict=True,
empty_lines_in_values=True, default_section='DEFAULT',
interpolation=<unset>, converters=<unset>):
Create the parser. When `defaults' is given, it is initialized into the
Create the parser. When `defaults` is given, it is initialized into the
dictionary or intrinsic defaults. The keys must be strings, the values
must be appropriate for %()s string interpolation.
When `dict_type' is given, it will be used to create the dictionary
When `dict_type` is given, it will be used to create the dictionary
objects for the list of sections, for the options within a section, and
for the default values.
When `delimiters' is given, it will be used as the set of substrings
When `delimiters` is given, it will be used as the set of substrings
that divide keys from values.
When `comment_prefixes' is given, it will be used as the set of
When `comment_prefixes` is given, it will be used as the set of
substrings that prefix comments in empty lines. Comments can be
indented.
When `inline_comment_prefixes' is given, it will be used as the set of
When `inline_comment_prefixes` is given, it will be used as the set of
substrings that prefix comments in non-empty lines.
When `strict` is True, the parser won't allow for any section or option
duplicates while reading from a single source (file, string or
dictionary). Default is True.
When `empty_lines_in_values' is False (default: True), each empty line
When `empty_lines_in_values` is False (default: True), each empty line
marks the end of an option. Otherwise, internal empty lines of
a multiline option are kept as part of the value.
When `allow_no_value' is True (default: False), options without
When `allow_no_value` is True (default: False), options without
values are accepted; the value presented for these is None.
When `default_section' is given, the name of the special section is
When `default_section` is given, the name of the special section is
named accordingly. By default it is called ``"DEFAULT"`` but this can
be customized to point to any other valid section name. Its current
value can be retrieved using the ``parser_instance.default_section``
Expand Down Expand Up @@ -87,7 +88,7 @@
read_file(f, filename=None)
Read and parse one configuration file, given as a file object.
The filename defaults to f.name; it is only used in error
messages (if f has no `name' attribute, the string `<???>' is used).
messages (if f has no `name` attribute, the string `<???>` is used).
read_string(string)
Read configuration from a given string.
Expand All @@ -103,9 +104,9 @@
Return a string value for the named option. All % interpolations are
expanded in the return values, based on the defaults passed into the
constructor and the DEFAULT section. Additional substitutions may be
provided using the `vars' argument, which must be a dictionary whose
contents override any pre-existing defaults. If `option' is a key in
`vars', the value from `vars' is used.
provided using the `vars` argument, which must be a dictionary whose
contents override any pre-existing defaults. If `option` is a key in
`vars`, the value from `vars` is used.
getint(section, options, raw=False, vars=None, fallback=_UNSET)
Like get(), but convert value to an integer.
Expand Down Expand Up @@ -134,7 +135,7 @@
write(fp, space_around_delimiters=True)
Write the configuration state in .ini format. If
`space_around_delimiters' is True (the default), delimiters
`space_around_delimiters` is True (the default), delimiters
between keys and values are surrounded by spaces.
"""

Expand Down Expand Up @@ -352,7 +353,7 @@ def __init__(self, filename, lineno, line):


# Used in parser getters to indicate the default behaviour when a specific
# option is not found it to raise an exception. Created to enable `None' as
# option is not found it to raise an exception. Created to enable `None` as
# a valid fallback value.
_UNSET = object()

Expand Down Expand Up @@ -386,7 +387,7 @@ class BasicInterpolation(Interpolation):
would resolve the "%(dir)s" to the value of dir. All reference
expansions are done late, on demand. If a user needs to use a bare % in
a configuration file, she can escape it by writing %%. Other % usage
is considered a user error and raises `InterpolationSyntaxError'."""
is considered a user error and raises `InterpolationSyntaxError`."""

_KEYCRE = re.compile(r"%\(([^)]+)\)s")

Expand Down Expand Up @@ -447,7 +448,7 @@ def _interpolate_some(self, parser, option, accum, rest, section, map,

class ExtendedInterpolation(Interpolation):
"""Advanced variant of interpolation, supports the syntax used by
`zc.buildout'. Enables interpolation between sections."""
`zc.buildout`. Enables interpolation between sections."""

_KEYCRE = re.compile(r"\$\{([^}]+)\}")

Expand Down Expand Up @@ -706,10 +707,10 @@ def read(self, filenames, encoding=None):
def read_file(self, f, source=None):
"""Like read() but the argument must be a file-like object.
The `f' argument must be iterable, returning one line at a time.
Optional second argument is the `source' specifying the name of the
file being read. If not given, it is taken from f.name. If `f' has no
`name' attribute, `<???>' is used.
The `f` argument must be iterable, returning one line at a time.
Optional second argument is the `source` specifying the name of the
file being read. If not given, it is taken from f.name. If `f` has no
`name` attribute, `<???>` is used.
"""
if source is None:
try:
Expand All @@ -733,7 +734,7 @@ def read_dict(self, dictionary, source='<dict>'):
All types held in the dictionary are converted to strings during
reading, including section names, option names and keys.
Optional second argument is the `source' specifying the name of the
Optional second argument is the `source` specifying the name of the
dictionary being read.
"""
elements_added = set()
Expand Down Expand Up @@ -766,15 +767,15 @@ def readfp(self, fp, filename=None):
def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
"""Get an option value for a given section.
If `vars' is provided, it must be a dictionary. The option is looked up
in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
If the key is not found and `fallback' is provided, it is used as
a fallback value. `None' can be provided as a `fallback' value.
If `vars` is provided, it must be a dictionary. The option is looked up
in `vars` (if provided), `section`, and in `DEFAULTSECT` in that order.
If the key is not found and `fallback` is provided, it is used as
a fallback value. `None` can be provided as a `fallback` value.
If interpolation is enabled and the optional argument `raw' is False,
If interpolation is enabled and the optional argument `raw` is False,
all interpolations are expanded in the return values.
Arguments `raw', `vars', and `fallback' are keyword only.
Arguments `raw`, `vars`, and `fallback` are keyword only.
The section DEFAULT is special.
"""
Expand Down Expand Up @@ -834,8 +835,8 @@ def items(self, section=_UNSET, raw=False, vars=None):
All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw' is true. Additional substitutions may be provided using the
`vars' argument, which must be a dictionary whose contents overrides
`raw` is true. Additional substitutions may be provided using the
`vars` argument, which must be a dictionary whose contents overrides
any pre-existing defaults.
The section DEFAULT is special.
Expand Down Expand Up @@ -877,8 +878,8 @@ def optionxform(self, optionstr):

def has_option(self, section, option):
"""Check for the existence of a given option in a given section.
If the specified `section' is None or an empty string, DEFAULT is
assumed. If the specified `section' does not exist, returns False."""
If the specified `section` is None or an empty string, DEFAULT is
assumed. If the specified `section` does not exist, returns False."""
if not section or section == self.default_section:
option = self.optionxform(option)
return option in self._defaults
Expand Down Expand Up @@ -906,7 +907,7 @@ def set(self, section, option, value=None):
def write(self, fp, space_around_delimiters=True):
"""Write an .ini-format representation of the configuration state.
If `space_around_delimiters' is True (the default), delimiters
If `space_around_delimiters` is True (the default), delimiters
between keys and values are surrounded by spaces.
Please note that comments in the original configuration file are not
Expand All @@ -924,7 +925,7 @@ def write(self, fp, space_around_delimiters=True):
self._sections[section].items(), d)

def _write_section(self, fp, section_name, section_items, delimiter):
"""Write a single section to the specified `fp'."""
"""Write a single section to the specified `fp`."""
fp.write("[{}]\n".format(section_name))
for key, value in section_items:
value = self._interpolation.before_write(self, section_name, key,
Expand Down Expand Up @@ -998,16 +999,16 @@ def _read(self, fp, fpname):
"""Parse a sectioned configuration file.
Each section in a configuration file contains a header, indicated by
a name in square brackets (`[]'), plus key/value options, indicated by
`name' and `value' delimited with a specific substring (`=' or `:' by
a name in square brackets (`[]`), plus key/value options, indicated by
`name` and `value` delimited with a specific substring (`=` or `:` by
default).
Values can span multiple lines, as long as they are indented deeper
than the first line of the value. Depending on the parser's mode, blank
lines may be treated as parts of multiline values or ignored.
Configuration files may include comments, prefixed by specific
characters (`#' and `;' by default). Comments may appear on their own
characters (`#` and `;` by default). Comments may appear on their own
in an otherwise empty line or may be entered in lines holding values or
section names. Please note that comments get stripped off when reading configuration files.
"""
Expand Down

0 comments on commit ed21112

Please sign in to comment.