From 7464e107694711e6cd27ca4048cd6dc0fcc66c52 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 28 Feb 2025 11:15:54 +0100 Subject: [PATCH 1/3] [configparser] Fix missing fallback argument in SectionProxy.get Closes: #13556 --- stdlib/@tests/test_cases/check_configparser.py | 5 +++++ stdlib/configparser.pyi | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 stdlib/@tests/test_cases/check_configparser.py diff --git a/stdlib/@tests/test_cases/check_configparser.py b/stdlib/@tests/test_cases/check_configparser.py new file mode 100644 index 000000000000..aaa2e3e059bd --- /dev/null +++ b/stdlib/@tests/test_cases/check_configparser.py @@ -0,0 +1,5 @@ +from configparser import SectionProxy +from typing_extensions import assert_type + +sp: SectionProxy +assert_type(sp.get("foo", fallback="hi"), str) diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index bc3e22771ca5..b6b647996352 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -320,7 +320,14 @@ class SectionProxy(MutableMapping[str, str]): # This is incompatible with MutableMapping so we ignore the type @overload # type: ignore[override] def get( - self, option: str, *, raw: bool = False, vars: _Section | None = None, _impl: Any | None = None, **kwargs: Any + self, + option: str, + fallback: None = None, + *, + raw: bool = False, + vars: _Section | None = None, + _impl: Any | None = None, + **kwargs: Any, ) -> str | None: ... @overload def get( From 5770c2cb9d02328eb55f70dc1b6f55469097ea9c Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 28 Feb 2025 11:19:16 +0100 Subject: [PATCH 2/3] Document Any while we're here --- stdlib/configparser.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/configparser.pyi b/stdlib/configparser.pyi index b6b647996352..8996c85d9a53 100644 --- a/stdlib/configparser.pyi +++ b/stdlib/configparser.pyi @@ -327,7 +327,7 @@ class SectionProxy(MutableMapping[str, str]): raw: bool = False, vars: _Section | None = None, _impl: Any | None = None, - **kwargs: Any, + **kwargs: Any, # passed to the underlying parser's get() method ) -> str | None: ... @overload def get( @@ -338,7 +338,7 @@ class SectionProxy(MutableMapping[str, str]): raw: bool = False, vars: _Section | None = None, _impl: Any | None = None, - **kwargs: Any, + **kwargs: Any, # passed to the underlying parser's get() method ) -> str | _T: ... # These are partially-applied version of the methods with the same names in # RawConfigParser; the stubs should be kept updated together From 235a44b333a41195240dc8bbe3abb1b306dcde4d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 28 Feb 2025 11:23:09 +0100 Subject: [PATCH 3/3] Try to make pyright happy --- stdlib/@tests/test_cases/check_configparser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/@tests/test_cases/check_configparser.py b/stdlib/@tests/test_cases/check_configparser.py index aaa2e3e059bd..28c355f385ff 100644 --- a/stdlib/@tests/test_cases/check_configparser.py +++ b/stdlib/@tests/test_cases/check_configparser.py @@ -1,5 +1,5 @@ -from configparser import SectionProxy +from configparser import RawConfigParser, SectionProxy from typing_extensions import assert_type -sp: SectionProxy +sp = SectionProxy(RawConfigParser(), "") assert_type(sp.get("foo", fallback="hi"), str)