Skip to content

gh-107625: configparser: Raise ParsingError if a key contains empty value #107651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix doc
  • Loading branch information
Agent-Hellboy committed Aug 5, 2023
commit ff8f339a9d79c7b438eca417323bed7cf46e4d8c
30 changes: 9 additions & 21 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,14 @@ ConfigParser Objects
instance will contain an empty dataset. An application which requires
initial values to be loaded from a file should load the required file or
files using :meth:`read_file` before calling :meth:`read` for any
optional files
optional files::

Raise a :exc:`ParsingError` instead of an :exc:`AttributeError`
Raise :exc:`ParsingError` instead of :exc:`AttributeError`
when the configuration contains a key without a corresponding value.
This change is intended to handle scenarios where a key lacks a value
in a configuration. Please note that it's not recommended to have extra
spaces or blank lines within sections of the configuration.
in a configuration which contains extra space or newline within a section.
Please note that it's not recommended to have extra spaces
or blank lines within sections of the configuration.

import configparser, os

Expand All @@ -1059,13 +1060,6 @@ ConfigParser Objects
.. versionadded:: 3.7
The *filenames* parameter accepts a :class:`bytes` object.

.. versionchanged:: 3.13
Parsing errors will result in a ParsingError being raised instead
of an AttributeError when encountering a key without a corresponding
value. This change is designed to handle situations where a key is
present without a value, particularly in scenarios not recommended,
such as having extra spaces or blank lines within sections.


.. method:: read_file(f, source=None)

Expand All @@ -1076,22 +1070,16 @@ ConfigParser Objects
not given and *f* has a :attr:`name` attribute, that is used for
*source*; the default is ``'<???>'``.

Raise a :exc:`ParsingError` instead of an :exc:`AttributeError`
Raise :exc:`ParsingError` instead of :exc:`AttributeError`
when the configuration contains a key without a corresponding value.
This change is intended to handle scenarios where a key lacks a value
in a configuration. Please note that it's not recommended to have extra
spaces or blank lines within sections of the configuration.
in a configuration which contains extra space or newline within a section.
Please note that it's not recommended to have extra spaces
or blank lines within sections of the configuration.

.. versionadded:: 3.2
Replaces :meth:`readfp`.

.. versionchanged:: 3.13
Parsing errors will result in a ParsingError being raised instead
of an AttributeError when encountering a key without a corresponding
value. This change is designed to handle situations where a key is
present without a value, particularly in scenarios not recommended,
such as having extra spaces or blank lines within sections.


.. method:: read_string(string, source='<string>')

Expand Down