Skip to content

Commit d2eb9ac

Browse files
authored
[configparser] Add several deprecated attributes (#14487)
1 parent 11907e2 commit d2eb9ac

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ tkinter.Tk.split # Exists at runtime, but missing from stubs
107107
# =======
108108

109109
_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
110-
configparser.ParsingError.filename
111110
enum.Enum._generate_next_value_
112111
importlib.abc.Finder.find_module
113112
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ importlib.metadata._meta.SimplePath.__truediv__ # Runtime definition of protoco
7070
# =======
7171

7272
_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
73-
configparser.ParsingError.filename
7473
enum.Enum._generate_next_value_
7574
importlib.abc.Finder.find_module
7675
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ typing_extensions.Sentinel.__call__
5454
# =======
5555

5656
_?bz2.BZ2Decompressor.__init__ # function does not accept parameters but C signature is set
57-
configparser.ParsingError.filename
5857
enum.Enum._generate_next_value_
5958
importlib.abc.Finder.find_module
6059
urllib.request.HTTPPasswordMgrWithPriorAuth.__init__ # Args are passed as is to super, so super args are specified

stdlib/configparser.pyi

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from _typeshed import MaybeNone, StrOrBytesPath, SupportsWrite
33
from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence
44
from re import Pattern
55
from typing import Any, ClassVar, Final, Literal, TypeVar, overload, type_check_only
6-
from typing_extensions import TypeAlias
6+
from typing_extensions import TypeAlias, deprecated
77

88
if sys.version_info >= (3, 14):
99
__all__ = (
@@ -271,6 +271,7 @@ class RawConfigParser(_Parser):
271271
def read_string(self, string: str, source: str = "<string>") -> None: ...
272272
def read_dict(self, dictionary: Mapping[str, Mapping[str, Any]], source: str = "<dict>") -> None: ...
273273
if sys.version_info < (3, 12):
274+
@deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `parser.read_file()` instead.")
274275
def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: ...
275276
# These get* methods are partially applied (with the same names) in
276277
# SectionProxy; the stubs should be kept updated together
@@ -331,7 +332,8 @@ class ConfigParser(RawConfigParser):
331332
) -> str | _T: ...
332333

333334
if sys.version_info < (3, 12):
334-
class SafeConfigParser(ConfigParser): ... # deprecated alias
335+
@deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `ConfigParser` instead.")
336+
class SafeConfigParser(ConfigParser): ...
335337

336338
class SectionProxy(MutableMapping[str, str]):
337339
def __init__(self, parser: RawConfigParser, name: str) -> None: ...
@@ -443,10 +445,22 @@ class ParsingError(Error):
443445
elif sys.version_info >= (3, 12):
444446
def __init__(self, source: str) -> None: ...
445447
else:
446-
def __init__(self, source: str | None = None, filename: str | None = None) -> None: ...
448+
@overload
449+
def __init__(self, source: str, filename: None = None) -> None: ...
450+
@overload
451+
@deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.")
452+
def __init__(self, source: None = None, filename: str = ...) -> None: ...
447453

448454
def append(self, lineno: int, line: str) -> None: ...
449455

456+
if sys.version_info < (3, 12):
457+
@property
458+
@deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.")
459+
def filename(self) -> str: ...
460+
@filename.setter
461+
@deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.")
462+
def filename(self, value: str) -> None: ...
463+
450464
class MissingSectionHeaderError(ParsingError):
451465
lineno: int
452466
line: str

0 commit comments

Comments
 (0)