Skip to content

Commit

Permalink
pythongh-89336: Remove configparser 3.12 deprecations.
Browse files Browse the repository at this point in the history
  • Loading branch information
gpshead committed May 8, 2022
1 parent ebb37fc commit f504766
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 68 deletions.
26 changes: 0 additions & 26 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1206,28 +1206,6 @@ ConfigParser Objects
names is stripped before :meth:`optionxform` is called.


.. method:: readfp(fp, filename=None)

.. deprecated:: 3.2
Use :meth:`read_file` instead.

.. versionchanged:: 3.2
:meth:`readfp` now iterates on *fp* instead of calling ``fp.readline()``.

For existing code calling :meth:`readfp` with arguments which don't
support iteration, the following generator may be used as a wrapper
around the file-like object::

def readline_generator(fp):
line = fp.readline()
while line:
yield line
line = fp.readline()

Instead of ``parser.readfp(fp)`` use
``parser.read_file(readline_generator(fp))``.


.. data:: MAX_INTERPOLATION_DEPTH

The maximum depth for recursive interpolation for :meth:`get` when the *raw*
Expand Down Expand Up @@ -1361,10 +1339,6 @@ Exceptions

Exception raised when errors occur attempting to parse a file.

.. versionchanged:: 3.2
The ``filename`` attribute and :meth:`__init__` argument were renamed to
``source`` for consistency.


.. rubric:: Footnotes

Expand Down
42 changes: 0 additions & 42 deletions Lib/configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,26 +312,6 @@ def __init__(self, source=None, filename=None):
self.errors = []
self.args = (source, )

@property
def filename(self):
"""Deprecated, use `source'."""
warnings.warn(
"The 'filename' attribute will be removed in Python 3.12. "
"Use 'source' instead.",
DeprecationWarning, stacklevel=2
)
return self.source

@filename.setter
def filename(self, value):
"""Deprecated, user `source'."""
warnings.warn(
"The 'filename' attribute will be removed in Python 3.12. "
"Use 'source' instead.",
DeprecationWarning, stacklevel=2
)
self.source = value

def append(self, lineno, line):
self.errors.append((lineno, line))
self.message += '\n\t[line %2d]: %s' % (lineno, line)
Expand Down Expand Up @@ -768,15 +748,6 @@ def read_dict(self, dictionary, source='<dict>'):
elements_added.add((section, key))
self.set(section, key, value)

def readfp(self, fp, filename=None):
"""Deprecated, use read_file instead."""
warnings.warn(
"This method will be removed in Python 3.12. "
"Use 'parser.read_file()' instead.",
DeprecationWarning, stacklevel=2
)
self.read_file(fp, source=filename)

def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
"""Get an option value for a given section.
Expand Down Expand Up @@ -1239,19 +1210,6 @@ def _read_defaults(self, defaults):
self._interpolation = hold_interpolation


class SafeConfigParser(ConfigParser):
"""ConfigParser alias for backwards compatibility purposes."""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
warnings.warn(
"The SafeConfigParser class has been renamed to ConfigParser "
"in Python 3.2. This alias will be removed in Python 3.12."
" Use ConfigParser directly instead.",
DeprecationWarning, stacklevel=2
)


class SectionProxy(MutableMapping):
"""A proxy for a single section from a parser."""

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``configparser`` module APIs deprecated to be removed in 3.12 have been
removed: The ``SafeConfigParser`` class alias, the ``ParsingError.filename``
property, and the ``ConfigParser.readfp`` method have all been removed.

0 comments on commit f504766

Please sign in to comment.