Fix default of dict.get (#13222)

This commit is contained in:
Stephen Morton
2025-03-09 13:44:27 +01:00
committed by GitHub
parent 0cdb5e969f
commit 846d167f51
4 changed files with 9 additions and 9 deletions
@@ -4,7 +4,6 @@
# Please keep sorted alphabetically
builtins.dict.get
collections\.ChainMap\.fromkeys # https://github.com/python/mypy/issues/17023
http.client.HTTPConnection.response_class # the actual type at runtime is abc.ABCMeta
importlib.abc.Loader.exec_module # See Lib/importlib/_abc.py. Might be defined for backwards compatibility
@@ -67,7 +67,7 @@ int_value = 1
assert_type(d_any["key"], Any)
assert_type(d_any.get("key"), Union[Any, None])
assert_type(d_any.get("key", None), Any)
assert_type(d_any.get("key", None), Union[Any, None])
assert_type(d_any.get("key", any_value), Any)
assert_type(d_any.get("key", str_value), Any)
assert_type(d_any.get("key", int_value), Any)
@@ -84,15 +84,16 @@ assert_type(d_str.get("key", int_value), Union[str, int])
result: str
result = d_any["key"]
result = d_any.get("key") # type: ignore[assignment]
result = d_any.get("key", None)
result = d_any.get("key", None) # type: ignore[assignment]
result = d_any.get("key", any_value)
result = d_any.get("key", str_value)
result = d_any.get("key", int_value)
result = d_str["key"]
result = d_str.get("key") # type: ignore[assignment]
result = d_str.get("key", None) # type: ignore[arg-type]
result = d_str.get("key", any_value)
result = d_str.get("key", None) # type: ignore[assignment]
# Pyright has str | None here, see https://github.com/microsoft/pyright/discussions/9570
result = d_str.get("key", any_value) # pyright: ignore[reportAssignmentType]
result = d_str.get("key", str_value)
result = d_str.get("key", int_value) # type: ignore[arg-type]
@@ -134,11 +135,11 @@ def test8() -> str:
def test9() -> str:
return d_str.get("key", None) # type: ignore[arg-type]
return d_str.get("key", None) # type: ignore[return-value]
def test10() -> str:
return d_str.get("key", any_value)
return d_str.get("key", any_value) # type: ignore[no-any-return]
def test11() -> str: