@@ -74,49 +74,42 @@ def test_iterable_tuple_overload(x: Iterable[tuple[int, str]]) -> dict[int, str]
7474assert_type (d_any .get ("key" ), Union [Any , None ])
7575assert_type (d_any .get ("key" , None ), Union [Any , None ])
7676assert_type (d_any .get ("key" , any_value ), Any )
77- assert_type (d_any .get ("key" , str_value ), Union [ Any , str ] )
78- assert_type (d_any .get ("key" , int_value ), Union [ Any , int ] )
77+ assert_type (d_any .get ("key" , str_value ), Any )
78+ assert_type (d_any .get ("key" , int_value ), Any )
7979
8080assert_type (d_str ["key" ], str )
8181assert_type (d_str .get ("key" ), Union [str , None ])
8282assert_type (d_str .get ("key" , None ), Union [str , None ])
8383# Pyright has str instead of Any here
84- assert_type (d_str .get ("key" , any_value ), Union [ str , Any ])
84+ assert_type (d_str .get ("key" , any_value ), Any ) # pyright: ignore[reportAssertTypeFailure]
8585assert_type (d_str .get ("key" , str_value ), str )
8686assert_type (d_str .get ("key" , int_value ), Union [str , int ])
8787
8888# Now with context!
8989result : str
9090result = d_any ["key" ]
91- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[assignment] here
92- result = d_any .get ("key" ) # type: ignore
93- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[assignment] here
94- result = d_any .get ("key" , None ) # type: ignore
91+ result = d_any .get ("key" ) # type: ignore[assignment]
92+ result = d_any .get ("key" , None ) # type: ignore[assignment]
9593result = d_any .get ("key" , any_value )
9694result = d_any .get ("key" , str_value )
97- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[assignment] here
98- result = d_any .get ("key" , int_value ) # type: ignore
95+ result = d_any .get ("key" , int_value )
9996
10097result = d_str ["key" ]
101- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[assignment] here
102- result = d_str .get ("key" ) # type: ignore
103- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[assignment] here
104- result = d_str .get ("key" , None ) # type: ignore
105- result = d_str .get ("key" , any_value )
98+ result = d_str .get ("key" ) # type: ignore[assignment]
99+ result = d_str .get ("key" , None ) # type: ignore[assignment]
100+ # Pyright has str | None here, see https://github.com/microsoft/pyright/discussions/9570
101+ result = d_str .get ("key" , any_value ) # pyright: ignore[reportAssignmentType]
106102result = d_str .get ("key" , str_value )
107103result = d_str .get ("key" , int_value ) # type: ignore[arg-type]
108104
109105
110- def test_get_literal (d : dict [Literal ["foo" , "bar" ], int ], dynamic_key : str ) -> None :
106+ def test_pop_literal (d : dict [Literal ["foo" , "bar" ], int ], key : str ) -> None :
111107 # Note: annotations also allow using keys of a disjoint type (e.g., int),
112108 # linters / type checkers are free to issue warnings in such cases.
113109 # statically, a .get(arg) is superfluous if the intersection of the
114110 # dict key type and the argument type is empty.
115111 # So we only test a case with non-empty intersection here.
116-
117- # check that dict wth Literal keys can get/pop a string key.
118- d .get (dynamic_key )
119- d .pop (dynamic_key )
112+ d .pop (key )
120113
121114
122115# Return values also make things weird
@@ -128,8 +121,7 @@ def test_get_literal(d: dict[Literal["foo", "bar"], int], dynamic_key: str) -> N
128121
129122
130123def test2 () -> str :
131- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[return-value] here
132- return d_any .get ("key" ) # type: ignore
124+ return d_any .get ("key" ) # type: ignore[return-value]
133125
134126
135127# def test3() -> str:
@@ -153,18 +145,15 @@ def test7() -> str:
153145
154146
155147def test8 () -> str :
156- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[return-value] here
157- return d_str .get ("key" ) # type: ignore
148+ return d_str .get ("key" ) # type: ignore[return-value]
158149
159150
160151def test9 () -> str :
161- # FIXME: https://github.com/python/mypy/issues/20576 prevents using ignore[return-value] here
162- return d_str .get ("key" , None ) # type: ignore
152+ return d_str .get ("key" , None ) # type: ignore[return-value]
163153
164154
165155def test10 () -> str :
166- # OK, return is Union[str, Any]
167- return d_str .get ("key" , any_value )
156+ return d_str .get ("key" , any_value ) # type: ignore[no-any-return]
168157
169158
170159def test11 () -> str :
0 commit comments