Skip to content

Commit 1fc41ae

Browse files
authored
bpo-45173 Remove configparser deprecations (GH-28292)
In the configparser module, these have been deprecated since Python 3.2: * the SafeConfigParser class, * the filename property of the ParsingError class, * the readfp method of the ConfigParser class,
1 parent 85dc53a commit 1fc41ae

File tree

5 files changed

+18
-94
lines changed

5 files changed

+18
-94
lines changed

Doc/library/configparser.rst

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,28 +1200,6 @@ ConfigParser Objects
12001200
names is stripped before :meth:`optionxform` is called.
12011201

12021202

1203-
.. method:: readfp(fp, filename=None)
1204-
1205-
.. deprecated:: 3.2
1206-
Use :meth:`read_file` instead.
1207-
1208-
.. versionchanged:: 3.2
1209-
:meth:`readfp` now iterates on *fp* instead of calling ``fp.readline()``.
1210-
1211-
For existing code calling :meth:`readfp` with arguments which don't
1212-
support iteration, the following generator may be used as a wrapper
1213-
around the file-like object::
1214-
1215-
def readline_generator(fp):
1216-
line = fp.readline()
1217-
while line:
1218-
yield line
1219-
line = fp.readline()
1220-
1221-
Instead of ``parser.readfp(fp)`` use
1222-
``parser.read_file(readline_generator(fp))``.
1223-
1224-
12251203
.. data:: MAX_INTERPOLATION_DEPTH
12261204

12271205
The maximum depth for recursive interpolation for :meth:`get` when the *raw*
@@ -1359,6 +1337,9 @@ Exceptions
13591337
The ``filename`` attribute and :meth:`__init__` argument were renamed to
13601338
``source`` for consistency.
13611339

1340+
.. versionchanged:: 3.11
1341+
The deprecated ``filename`` attribute was removed.
1342+
13621343

13631344
.. rubric:: Footnotes
13641345

Doc/whatsnew/3.11.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ Removed
284284
the ``l*gettext()`` functions.
285285
(Contributed by Dong-hee Na and Serhiy Storchaka in :issue:`44235`.)
286286

287+
* Remove from the :mod:`configparser` module:
288+
the :class:`SafeConfigParser` class,
289+
the :attr:`filename` property of the :class:`ParsingError` class,
290+
the :meth:`readfp` method of the :class:`ConfigParser` class,
291+
deprecated since Python 3.2.
292+
(Contributed by Hugo van Kemenade in :issue:`45173`.)
293+
287294

288295
Optimizations
289296
=============

Lib/configparser.py

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@
146146
import os
147147
import re
148148
import sys
149-
import warnings
150149

151150
__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
152151
"NoOptionError", "InterpolationError", "InterpolationDepthError",
153152
"InterpolationMissingOptionError", "InterpolationSyntaxError",
154153
"ParsingError", "MissingSectionHeaderError",
155-
"ConfigParser", "SafeConfigParser", "RawConfigParser",
154+
"ConfigParser", "RawConfigParser",
156155
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
157156
"LegacyInterpolation", "SectionProxy", "ConverterMapping",
158157
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
@@ -312,26 +311,6 @@ def __init__(self, source=None, filename=None):
312311
self.errors = []
313312
self.args = (source, )
314313

315-
@property
316-
def filename(self):
317-
"""Deprecated, use `source'."""
318-
warnings.warn(
319-
"The 'filename' attribute will be removed in future versions. "
320-
"Use 'source' instead.",
321-
DeprecationWarning, stacklevel=2
322-
)
323-
return self.source
324-
325-
@filename.setter
326-
def filename(self, value):
327-
"""Deprecated, user `source'."""
328-
warnings.warn(
329-
"The 'filename' attribute will be removed in future versions. "
330-
"Use 'source' instead.",
331-
DeprecationWarning, stacklevel=2
332-
)
333-
self.source = value
334-
335314
def append(self, lineno, line):
336315
self.errors.append((lineno, line))
337316
self.message += '\n\t[line %2d]: %s' % (lineno, line)
@@ -754,15 +733,6 @@ def read_dict(self, dictionary, source='<dict>'):
754733
elements_added.add((section, key))
755734
self.set(section, key, value)
756735

757-
def readfp(self, fp, filename=None):
758-
"""Deprecated, use read_file instead."""
759-
warnings.warn(
760-
"This method will be removed in future versions. "
761-
"Use 'parser.read_file()' instead.",
762-
DeprecationWarning, stacklevel=2
763-
)
764-
self.read_file(fp, source=filename)
765-
766736
def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
767737
"""Get an option value for a given section.
768738
@@ -1225,19 +1195,6 @@ def _read_defaults(self, defaults):
12251195
self._interpolation = hold_interpolation
12261196

12271197

1228-
class SafeConfigParser(ConfigParser):
1229-
"""ConfigParser alias for backwards compatibility purposes."""
1230-
1231-
def __init__(self, *args, **kwargs):
1232-
super().__init__(*args, **kwargs)
1233-
warnings.warn(
1234-
"The SafeConfigParser class has been renamed to ConfigParser "
1235-
"in Python 3.2. This alias will be removed in future versions."
1236-
" Use ConfigParser directly instead.",
1237-
DeprecationWarning, stacklevel=2
1238-
)
1239-
1240-
12411198
class SectionProxy(MutableMapping):
12421199
"""A proxy for a single section from a parser."""
12431200

Lib/test/test_configparser.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,13 +1612,6 @@ def test_parsing_error(self):
16121612
"and `source'. Use `source'.")
16131613
error = configparser.ParsingError(filename='source')
16141614
self.assertEqual(error.source, 'source')
1615-
with warnings.catch_warnings(record=True) as w:
1616-
warnings.simplefilter("always", DeprecationWarning)
1617-
self.assertEqual(error.filename, 'source')
1618-
error.filename = 'filename'
1619-
self.assertEqual(error.source, 'filename')
1620-
for warning in w:
1621-
self.assertTrue(warning.category is DeprecationWarning)
16221615

16231616
def test_interpolation_validation(self):
16241617
parser = configparser.ConfigParser()
@@ -1637,27 +1630,6 @@ def test_interpolation_validation(self):
16371630
self.assertEqual(str(cm.exception), "bad interpolation variable "
16381631
"reference '%(()'")
16391632

1640-
def test_readfp_deprecation(self):
1641-
sio = io.StringIO("""
1642-
[section]
1643-
option = value
1644-
""")
1645-
parser = configparser.ConfigParser()
1646-
with warnings.catch_warnings(record=True) as w:
1647-
warnings.simplefilter("always", DeprecationWarning)
1648-
parser.readfp(sio, filename='StringIO')
1649-
for warning in w:
1650-
self.assertTrue(warning.category is DeprecationWarning)
1651-
self.assertEqual(len(parser), 2)
1652-
self.assertEqual(parser['section']['option'], 'value')
1653-
1654-
def test_safeconfigparser_deprecation(self):
1655-
with warnings.catch_warnings(record=True) as w:
1656-
warnings.simplefilter("always", DeprecationWarning)
1657-
parser = configparser.SafeConfigParser()
1658-
for warning in w:
1659-
self.assertTrue(warning.category is DeprecationWarning)
1660-
16611633
def test_sectionproxy_repr(self):
16621634
parser = configparser.ConfigParser()
16631635
parser.read_string("""
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Remove from the :mod:`configparser` module:
2+
the :class:`SafeConfigParser` class,
3+
the :attr:`filename` property of the :class:`ParsingError` class,
4+
the :meth:`readfp` method of the :class:`ConfigParser` class,
5+
deprecated since Python 3.2.
6+
7+
Patch by Hugo van Kemenade.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy