You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,7 +79,34 @@ This was contributed by Jukka Lehtosalo (PR [18727](https://github.com/python/my
79
79
80
80
Mypy can now detect additional errors in code that uses `Any` types or has missing function annotations.
81
81
82
-
*`dict.get`
82
+
When calling `dict.get(x, None)` on an object of type `dict[str, Any]`, this
83
+
now results in an optional type (in the past it was `Any`):
84
+
85
+
```python
86
+
deff(d: dict[str, Any]) -> int:
87
+
# Error: Return value has type "Any | None" but expected "int"
88
+
return d.get("x", None)
89
+
```
90
+
91
+
Type narrowing using assignments can result in more precise types in
92
+
the presence of `Any` types:
93
+
94
+
```python
95
+
deffoo(): ...
96
+
97
+
defbar(n: int) -> None:
98
+
x = foo()
99
+
# Type of 'x' is 'Any' here
100
+
if n >5:
101
+
x =str(n)
102
+
# Type of 'x' is 'str' here
103
+
```
104
+
105
+
When using `--check-untyped-defs`, unannotated overrides are now
106
+
checked more strictly against superclass definitions.
107
+
108
+
Related PRs:
109
+
83
110
* Use union types instead of join in binder (Ivan Levkivskyi, PR [18538](https://github.com/python/mypy/pull/18538))
84
111
* Check superclass compatibility of untyped methods if `--check-untyped-defs` is set (Stanislav Terliakov, PR [18970](https://github.com/python/mypy/pull/18970))
0 commit comments