Skip to content

Make configparser.RawConfigParser use SectionProxy where appropriate #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions stdlib/3/configparser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# reading configparser.py.

import sys
from typing import (MutableMapping, Mapping, Dict, Sequence, List, Union,
Iterable, Iterator, Callable, Any, IO, overload, Optional,
Pattern, TypeVar)
from typing import (AbstractSet, MutableMapping, Mapping, Dict, Sequence, List,
Union, Iterable, Iterator, Callable, Any, IO, overload,
Optional, Pattern, TypeVar)
# Types only used in type comments only
from typing import Optional, Tuple # noqa

Expand Down Expand Up @@ -70,7 +70,7 @@ class RawConfigParser(_parser):

def __len__(self) -> int: ...

def __getitem__(self, section: str) -> _section: ...
def __getitem__(self, section: str) -> SectionProxy: ...

def __setitem__(self, section: str, options: _section) -> None: ...

Expand Down Expand Up @@ -112,8 +112,11 @@ class RawConfigParser(_parser):
def get(self, section: str, option: str, *, raw: bool = ..., vars: _section = ..., fallback: str = ...) -> str: # type: ignore
...

# This is incompatible with Mapping so we ignore the type.
def items(self, section: str = ..., raw: bool = ..., vars: _section = ...) -> Iterable[Tuple[str, _section]]: ... # type: ignore
@overload
def items(self, *, raw: bool = ..., vars: _section = ...) -> AbstractSet[Tuple[str, SectionProxy]]: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, return types that are as concrete as possible, and accept types in arguments that are as generic as possible.


@overload
def items(self, section: str, raw: bool = ..., vars: _section = ...) -> List[Tuple[str, str]]: ...

def set(self, section: str, option: str, value: str) -> None: ...

Expand Down