Skip to content

Commit b065c73

Browse files
committed
Document Any-related type checking improvements
1 parent 60c1c7f commit b065c73

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

CHANGELOG.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,34 @@ This was contributed by Jukka Lehtosalo (PR [18727](https://github.com/python/my
7979

8080
Mypy can now detect additional errors in code that uses `Any` types or has missing function annotations.
8181

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+
def f(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+
def foo(): ...
96+
97+
def bar(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+
83110
* Use union types instead of join in binder (Ivan Levkivskyi, PR [18538](https://github.com/python/mypy/pull/18538))
84111
* Check superclass compatibility of untyped methods if `--check-untyped-defs` is set (Stanislav Terliakov, PR [18970](https://github.com/python/mypy/pull/18970))
85112

0 commit comments

Comments
 (0)