8000 Add changelog for 1.16 by JukkaL · Pull Request #19138 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Add changelog for 1.16 #19138

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

Merged
merged 20 commits into from
May 29, 2025
Merged
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
Prev Previous commit
Next Next commit
Add content for major changes and other smaller updates
  • Loading branch information
JukkaL committed May 23, 2025
commit 60c1c7f054b7f74b0f8a0df209909ce5f97cd977
91 changes: 72 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,94 @@

### Different Property Getter and Setter Types

Mypy now supports using different types for property getter and setter.
Mypy now supports using different types for a property getter and setter:

```python
class A:
value: int
_value: int

@property
def f(self) -> int:
return self.value
@f.setter
def f(self, x: str | int) -> None:
def foo(self) -> int:
return self._value

@foo.setter
def foo(self, x: str | int) -> None:
try:
self.value = int(x)
self._value = int(x)
except ValueError:
raise Exception(f"'{x}' is not a valid value for 'f'")
raise Exception(f"'{x}' is not a valid value for 'foo'")
```
Contributed by Ivan Levkivskyi (PR [18510](https://github.com/python/mypy/pull/18510))
This was contributed by Ivan Levkivskyi (PR [18510](https://github.com/python/mypy/pull/18510)).

### Flexible Variable Redefinitions (Experimental)

* Add flag to allow more flexible variable redefinition (Jukka Lehtosalo, PR [18727](https://github.com/python/mypy/pull/18727))
Mypy now allows unannotated variables to be freely redefined with
different types when using the experimental `--allow-redefinition-new`
flag. You will also need to enable `--local-partial-types`. Mypy will
now infer a union type when different types are assigned to a
variable:

```py
# mypy: allow-redefinition-new, local-partial-types

def f(n: int, b: bool) -> int | str:
if b:
x = n
else:
x = str(n)
# Type of 'x' is int | str here.
return x
```

Without the new flag, mypy only supports inferring optional types (`X
| None`) from multiple assignments, but now mypy can infer arbitrary
union types.

An unannotated variable can now also have different types in different
code locations:

```py
# mypy: allow-redefinition-new, local-partial-types
...

if cond():
for x in range(n):
# Type of 'x' is 'int' here
...
else:
for x in ['a', 'b']:
# Type of 'x' is 'str' here
...
```

We are planning to turn this flag on by default in mypy 2.0, along
with `--local-partial-types`. The feature is still experimental and
has known issues, and the semantics may still change in the
future. You may need to update or add type annotations when switching
to the new behavior, but if you encounter anything unexpected, please
create a GitHub issue.

This was contributed by Jukka Lehtosalo (PR [18727](https://github.com/python/mypy/pull/18727)).

### Stricter Type Checking with Imprecise Types

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

* `dict.get`
* Use union types instead of join in binder (Ivan Levkivskyi, PR [18538](https://github.com/python/mypy/pull/18538))
* Check superclass compatibility of untyped methods if `--check-untyped-defs` is set (Stanislav Terliakov, PR [18970](https://github.com/python/mypy/pull/18970))

### Improvements to Attribute Resolution

This release includes various fixes to inconsistent resolution of attribute access.
This release includes several fixes to inconsistent resolution of attribute, method and descriptor types.

* Consolidate descriptor handling in checkmember.py (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))
* Use checkmember.py to check multiple inheritance (Ivan Levkivskyi, PR [18876](https://github.com/python/mypy/pull/18876))
* Use checkmember.py to check method override (Ivan Levkivskyi, PR [18870](https://github.com/python/mypy/pull/18870))
* Consolidate descriptor handling (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))
* Make multiple inheritance checking use common semantics (Ivan Levkivskyi, PR [18876](https://github.com/python/mypy/pull/18876))
* Make method override checking use common semantics (Ivan Levkivskyi, PR [18870](https://github.com/python/mypy/pull/18870))
* Fix descriptor overload selection (Ivan Levkivskyi, PR [18868](https://github.com/python/mypy/pull/18868))
* Handle union types when binding self (Ivan Levkivskyi, PR [18867](https://github.com/python/mypy/pull/18867))
* Use checkmember.py to check variable overrides (Ivan Levkivskyi, PR [18847](https://github.com/python/mypy/pull/18847))
* Consolidate descriptor handling in checkmember.py (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))
* Handle union types when binding `self` (Ivan Levkivskyi, PR [18867](https://github.com/python/mypy/pull/18867))
* Make variable override checking use common semantics (Ivan Levkivskyi, PR [18847](https://github.com/python/mypy/pull/18847))
* Make descriptor handling behave consistently (Ivan Levkivskyi, PR [18831](https://github.com/python/mypy/pull/18831))

### Make Implementation for Abstract Overloads Optional

Expand All @@ -61,20 +108,26 @@ This release includes various fixes to inconsistent resolution of attribute acce
It's now possible to selectively disable warnings generated from
[`warnings.deprecated`](https://docs.python.org/3/library/warnings.html#warnings.deprecated)
using the [`--deprecated-calls-exclude`](https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-deprecated-calls-exclude)
option.
option:

```python
# mypy --enable-error-code deprecated
# --deprecated-calls-exclude=foo.A
import foo

foo.A().func() # OK, the deprecated warning is ignored
```

```python
# file foo.py

from typing_extensions import deprecated

class A:
@deprecated("Use A.func2 instead")
def func(self): pass

...
```

Contributed by Marc Mueller (PR [18641](https://github.com/python/mypy/pull/18641))
Expand Down
0