Hello, I’ve subclassed the ConfigParser class whose get()
method is typed as follows (pyi):
def get(self, section: _SectionName, option: str, *, raw: bool = False, vars: _Section | None = None, fallback: _T) -> str | _T: ...
Note the _SectionName
which is defined as (pyi):
class _UNNAMED_SECTION: ...
UNNAMED_SECTION: _UNNAMED_SECTION
_SectionName: TypeAlias = str | _UNNAMED_SECTION
Being a “private” module type I tried to create my own type like so:
if TYPE_CHECKING:
# fails: from configparser import UNNAMED_SECTION # [valid-type]
# See also: https://github.com/python/typeshed/tree/main/stdlib/_typeshed
# fails: from _typeshed import configparser # [attr-defined]
# fails: from _typeshed import _SectionName # [attr-defined]
# fails: from _typeshed.configparser import _SectionName # [import-not-found]
# fails: from _typeshed import UNNAMED_SECTION # [attr-defined]
from _typeshed.configparser import UNNAMED_SECTION # [import-not-found]
SectionName: TypeAlias = str | UNNAMED_SECTION
However, I can’t seem to be able to import UNNAMED_SECTION
or _SectionName
, and I’m running out of ideas.
How would I type this method in a subclass? This is for Python 3.13 and mypy v1.16.0.
Thank you!