Skip to content

Commit 1a3957a

Browse files
Merge branch 'master' into fix_typevar_default
2 parents 76c0123 + 4301be1 commit 1a3957a

File tree

8 files changed

+57
-47
lines changed

8 files changed

+57
-47
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
## Next Release
44

5-
## Mypy 1.18
5+
## Mypy 1.18.1
66

7-
We’ve just uploaded mypy 1.18 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
7+
We’ve just uploaded mypy 1.18.1 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)).
88
Mypy is a static type checker for Python. This release includes new features, performance
99
improvements and bug fixes. You can install it as follows:
1010

@@ -14,7 +14,7 @@ You can read the full documentation for this release on [Read the Docs](http://m
1414

1515
### Mypy Performance Improvements
1616

17-
Mypy 1.18 includes numerous performance improvements, resulting in about 40% speedup
17+
Mypy 1.18.1 includes numerous performance improvements, resulting in about 40% speedup
1818
compared to 1.17 when type checking mypy itself. In extreme cases, the improvement
1919
can be 10x or higher. The list below is an overview of the various mypy optimizations.
2020
Many mypyc improvements (discussed in a separate section below) also improve performance.
@@ -283,6 +283,12 @@ Related PRs:
283283

284284
Please see [git log](https://github.com/python/typeshed/commits/main?after=2480d7e7c74493a024eaf254c5d2c6f452c80ee2+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
285285

286+
### Mypy 1.18.2
287+
288+
- Fix crash on recursive alias (Ivan Levkivskyi, PR [19845](https://github.com/python/mypy/pull/19845))
289+
- Add additional guidance for stubtest errors when runtime is `object.__init__` (Stephen Morton, PR [19733](https://github.com/python/mypy/pull/19733))
290+
- Fix handling of None values in f-string expressions in mypyc (BobTheBuidler, PR [19846](https://github.com/python/mypy/pull/19846))
291+
286292
### Acknowledgements
287293

288294
Thanks to all mypy contributors who contributed to this release:

test-data/unit/fixtures/typing-async.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
123123
@overload
124124
def get(self, k: T, default: Union[T_co, V]) -> Union[T_co, V]: pass
125125

126-
class ContextManager(Generic[T]):
127-
def __enter__(self) -> T: pass
126+
class ContextManager(Generic[T_co]):
127+
def __enter__(self) -> T_co: pass
128128
# Use Any because not all the precise types are in the fixtures.
129129
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass
130130

131-
class AsyncContextManager(Generic[T]):
132-
def __aenter__(self) -> Awaitable[T]: pass
131+
class AsyncContextManager(Generic[T_co]):
132+
def __aenter__(self) -> Awaitable[T_co]: pass
133133
# Use Any because not all the precise types are in the fixtures.
134134
def __aexit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Awaitable[Any]: pass
135135

test-data/unit/fixtures/typing-full.pyi

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Literal: _SpecialForm
4444

4545
T = TypeVar('T')
4646
T_co = TypeVar('T_co', covariant=True)
47-
T_contra = TypeVar('T_contra', contravariant=True)
47+
R_co = TypeVar('R_co', covariant=True)
48+
S_contra = TypeVar('S_contra', contravariant=True)
4849
U = TypeVar('U')
4950
V = TypeVar('V')
5051
S = TypeVar('S')
@@ -82,9 +83,9 @@ class Iterator(Iterable[T_co], Protocol):
8283
@abstractmethod
8384
def __next__(self) -> T_co: pass
8485

85-
class Generator(Iterator[T], Generic[T, U, V]):
86+
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
8687
@abstractmethod
87-
def send(self, value: U) -> T: pass
88+
def send(self, value: S_contra) -> T_co: pass
8889

8990
@abstractmethod
9091
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
@@ -93,35 +94,40 @@ class Generator(Iterator[T], Generic[T, U, V]):
9394
def close(self) -> None: pass
9495

9596
@abstractmethod
96-
def __iter__(self) -> 'Generator[T, U, V]': pass
97+
def __iter__(self) -> 'Generator[T_co, S_contra, R_co]': pass
9798

98-
class AsyncGenerator(AsyncIterator[T], Generic[T, U]):
99+
class AsyncGenerator(AsyncIterator[T_co], Generic[T_co, S_contra]):
99100
@abstractmethod
100-
def __anext__(self) -> Awaitable[T]: pass
101+
def __anext__(self) -> Awaitable[T_co]: pass
101102

102103
@abstractmethod
103-
def asend(self, value: U) -> Awaitable[T]: pass
104+
def asend(self, value: S_contra) -> Awaitable[T_co]: pass
104105

105106
@abstractmethod
106-
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T]: pass
107+
def athrow(self, typ: Any, val: Any=None, tb: Any=None) -> Awaitable[T_co]: pass
107108

108109
@abstractmethod
109-
def aclose(self) -> Awaitable[T]: pass
110+
def aclose(self) -> Awaitable[T_co]: pass
110111

111112
@abstractmethod
112-
def __aiter__(self) -> 'AsyncGenerator[T, U]': pass
113+
def __aiter__(self) -> 'AsyncGenerator[T_co, S_contra]': pass
113114

114115
@runtime_checkable
115-
class Awaitable(Protocol[T]):
116+
class Awaitable(Protocol[T_co]):
116117
@abstractmethod
117-
def __await__(self) -> Generator[Any, Any, T]: pass
118+
def __await__(self) -> Generator[Any, Any, T_co]: pass
118119

119-
class AwaitableGenerator(Generator[T, U, V], Awaitable[V], Generic[T, U, V, S], metaclass=ABCMeta):
120+
class AwaitableGenerator(
121+
Awaitable[R_co],
122+
Generator[T_co, S_contra, R_co],
123+
Generic[T_co, S_contra, R_co, S],
124+
metaclass=ABCMeta
125+
):
120126
pass
121127

122-
class Coroutine(Awaitable[V], Generic[T, U, V]):
128+
class Coroutine(Awaitable[R_co], Generic[T_co, S_contra, R_co]):
123129
@abstractmethod
124-
def send(self, value: U) -> T: pass
130+
def send(self, value: S_contra) -> T_co: pass
125131

126132
@abstractmethod
127133
def throw(self, typ: Any, val: Any=None, tb: Any=None) -> None: pass
@@ -130,15 +136,15 @@ class Coroutine(Awaitable[V], Generic[T, U, V]):
130136
def close(self) -> None: pass
131137

132138
@runtime_checkable
133-
class AsyncIterable(Protocol[T]):
139+
class AsyncIterable(Protocol[T_co]):
134140
@abstractmethod
135-
def __aiter__(self) -> 'AsyncIterator[T]': pass
141+
def __aiter__(self) -> 'AsyncIterator[T_co]': pass
136142

137143
@runtime_checkable
138-
class AsyncIterator(AsyncIterable[T], Protocol):
139-
def __aiter__(self) -> 'AsyncIterator[T]': return self
144+
class AsyncIterator(AsyncIterable[T_co], Protocol):
145+
def __aiter__(self) -> 'AsyncIterator[T_co]': return self
140146
@abstractmethod
141-
def __anext__(self) -> Awaitable[T]: pass
147+
def __anext__(self) -> Awaitable[T_co]: pass
142148

143149
class Sequence(Iterable[T_co], Container[T_co]):
144150
@abstractmethod

test-data/unit/fixtures/typing-medium.pyi

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ Self = 0
3232

3333
T = TypeVar('T')
3434
T_co = TypeVar('T_co', covariant=True)
35-
T_contra = TypeVar('T_contra', contravariant=True)
36-
U = TypeVar('U')
37-
V = TypeVar('V')
38-
S = TypeVar('S')
35+
R_co = TypeVar('R_co', covariant=True)
36+
S_contra = TypeVar('S_contra', contravariant=True)
3937

4038
# Note: definitions below are different from typeshed, variances are declared
4139
# to silence the protocol variance checks. Maybe it is better to use type: ignore?
@@ -49,8 +47,8 @@ class Iterable(Protocol[T_co]):
4947
class Iterator(Iterable[T_co], Protocol):
5048
def __next__(self) -> T_co: pass
5149

52-
class Generator(Iterator[T], Generic[T, U, V]):
53-
def __iter__(self) -> 'Generator[T, U, V]': pass
50+
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
51+
def __iter__(self) -> 'Generator[T_co, S_contra, R_co]': pass
5452

5553
class Sequence(Iterable[T_co]):
5654
def __getitem__(self, n: Any) -> T_co: pass
@@ -65,8 +63,8 @@ class SupportsInt(Protocol):
6563
class SupportsFloat(Protocol):
6664
def __float__(self) -> float: pass
6765

68-
class ContextManager(Generic[T]):
69-
def __enter__(self) -> T: pass
66+
class ContextManager(Generic[T_co]):
67+
def __enter__(self) -> T_co: pass
7068
# Use Any because not all the precise types are in the fixtures.
7169
def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> Any: pass
7270

test-data/unit/fixtures/typing-namedtuple.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Iterable(Generic[T_co]): pass
1818
class Iterator(Iterable[T_co]): pass
1919
class Sequence(Iterable[T_co]): pass
2020
class Mapping(Iterable[KT], Generic[KT, T_co]):
21-
def keys(self) -> Iterable[T]: pass # Approximate return type
22-
def __getitem__(self, key: T) -> T_co: pass
21+
def keys(self) -> Iterable[KT]: pass # Approximate return type
22+
def __getitem__(self, key: KT) -> T_co: pass
2323

2424
class NamedTuple(tuple[Any, ...]):
2525
_fields: ClassVar[tuple[str, ...]]

test-data/unit/fixtures/typing-override.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Iterable(Generic[T_co]): pass
1818
class Iterator(Iterable[T_co]): pass
1919
class Sequence(Iterable[T_co]): pass
2020
class Mapping(Iterable[KT], Generic[KT, T_co]):
21-
def keys(self) -> Iterable[T]: pass # Approximate return type
22-
def __getitem__(self, key: T) -> T_co: pass
21+
def keys(self) -> Iterable[KT]: pass # Approximate return type
22+
def __getitem__(self, key: KT) -> T_co: pass
2323

2424
def override(__arg: T) -> T: ...
2525

test-data/unit/fixtures/typing-typeddict.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Mapping(Iterable[T], Generic[T, T_co], metaclass=ABCMeta):
6161
def __len__(self) -> int: ...
6262
def __contains__(self, arg: object) -> int: pass
6363

64-
class MutableMapping(Mapping[T, T_co], Generic[T, T_co], metaclass=ABCMeta):
64+
class MutableMapping(Mapping[T, V], Generic[T, V], metaclass=ABCMeta):
6565
# Other methods are not used in tests.
6666
def clear(self) -> None: ...
6767

test-data/unit/lib-stub/typing.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ TYPE_CHECKING = 0
3535

3636
T = TypeVar('T')
3737
T_co = TypeVar('T_co', covariant=True)
38-
U = TypeVar('U')
39-
V = TypeVar('V')
38+
S_contra = TypeVar('S_contra', contravariant=True)
39+
R_co = TypeVar('R_co', covariant=True)
4040

4141
class Iterable(Protocol[T_co]):
4242
def __iter__(self) -> Iterator[T_co]: pass
4343

4444
class Iterator(Iterable[T_co], Protocol):
4545
def __next__(self) -> T_co: pass
4646

47-
class Generator(Iterator[T], Generic[T, U, V]):
48-
def __iter__(self) -> Generator[T, U, V]: pass
47+
class Generator(Iterator[T_co], Generic[T_co, S_contra, R_co]):
48+
def __iter__(self) -> Generator[T_co, S_contra, R_co]: pass
4949

5050
class Sequence(Iterable[T_co]):
5151
def __getitem__(self, n: Any) -> T_co: pass
@@ -56,10 +56,10 @@ class Mapping(Iterable[T], Generic[T, T_co]):
5656
def keys(self) -> Iterable[T]: pass # Approximate return type
5757
def __getitem__(self, key: T) -> T_co: pass
5858

59-
class Awaitable(Protocol[T]):
60-
def __await__(self) -> Generator[Any, Any, T]: pass
59+
class Awaitable(Protocol[T_co]):
60+
def __await__(self) -> Generator[Any, Any, T_co]: pass
6161

62-
class Coroutine(Awaitable[V], Generic[T, U, V]): pass
62+
class Coroutine(Awaitable[R_co], Generic[T_co, S_contra, R_co]): pass
6363

6464
def final(meth: T) -> T: pass
6565

0 commit comments

Comments
 (0)