8000 Alternate method of handling dict.get default value by tungol · Pull Request #13224 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Alternate method of handling dict.get default value #13224

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Alternate method of handling dict.get default value
  • Loading branch information
tungol committed Dec 8, 2024
commit 353c07a081afa240e65624f503b960eaa9432698
4 changes: 2 additions & 2 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _collections_abc.AsyncGenerator.ag_frame
_collections_abc.AsyncGenerator.ag_running
asyncio.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
asyncio.base_events.BaseEventLoop.subprocess_exec # BaseEventLoop adds several parameters and stubtest fails on the difference if we add them
builtins.dict.get
# builtins.dict.get
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
configparser.SectionProxy.__getattr__ # SectionProxy can have arbitrary attributes when custom converters are used
configparser.SectionProxy.getboolean # SectionProxy get functions are set in __init__
Expand Down Expand Up @@ -190,7 +190,7 @@ _collections_abc.Generator.gi_frame
_collections_abc.Generator.gi_running
_collections_abc.Generator.gi_yieldfrom
_collections_abc.Mapping.__reversed__ # set to None at runtime for a better error message
_collections_abc.Mapping.get # Adding None to the Union messed up mypy
# _collections_abc.Mapping.get # Adding None to the Union messed up mypy
_collections_abc.Sequence.index # Supporting None in end is not mandatory

# Adding these reflected dunders to `typing.AbstractSet` causes a large number of false-positives. See #7414.
Expand Down
2 changes: 2 additions & 0 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,8 @@ class dict(MutableMapping[_KT, _VT]):
@overload
def get(self, key: _KT, default: _VT, /) -> _VT: ...
@overload
def get(self, key: _KT, default: None, /) -> _VT | None: ...
@overload
def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
@overload
def pop(self, key: _KT, /) -> _VT: ...
Expand Down
4 changes: 4 additions & 0 deletions stdlib/importlib/metadata/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ if sys.version_info >= (3, 10) and sys.version_info < (3, 12):
@overload
def get(self, name: _KT) -> _VT | None: ...
@overload
def get(self, name: _KT, default: _VT) -> _VT: ...
@overload
def get(self, name: _KT, default: None) -> _VT | None: ...
@overload
def get(self, name: _KT, default: _T) -> _VT | _T: ...
def __iter__(self) -> Iterator[_KT]: ...
def __contains__(self, *args: object) -> bool: ...
Expand Down
6 changes: 5 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,11 @@ class Mapping(Collection[_KT], Generic[_KT, _VT_co]):
@overload
def get(self, key: _KT, /) -> _VT_co | None: ...
@overload
def get(self, key: _KT, /, default: _VT_co | _T) -> _VT_co | _T: ...
def get(self, key: _KT, /, default: _VT_co) -> _VT_co: ... # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] # Covariant variable as parameter
@overload
def get(self, key: _KT, /, default: None) -> _VT_co | None: ...
@overload
def get(self, key: _KT, /, default: _T) -> _VT_co | _T: ...
def items(self) -> ItemsView[_KT, _VT_co]: ...
def keys(self) -> KeysView[_KT]: ...
def values(self) -> ValuesView[_VT_co]: ...
Expand Down
Loading
0