Skip to content

Commit 4864335

Browse files
AlexWaygoodsrittau
andauthored
Update ty to 0.0.83 (#16470)
Co-authored-by: Sebastian Rittau <sebastian.rittau@zfutura.de>
1 parent cd89128 commit 4864335

5 files changed

Lines changed: 47 additions & 12 deletions

File tree

‎requirements-tests.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
mypy==2.3.1
44
pyrefly==1.3.1
55
pyright==1.1.414
6-
ty==0.0.59
6+
ty==0.0.83
77

88
# Libraries used by our various scripts.
99
aiohttp==3.14.3

‎stdlib/_typeshed/__init__.pyi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class SupportsTrunc(Protocol):
170170

171171
# The second and third overload could technically be combined, but splitting
172172
# them works better with some type checkers.
173-
class SupportsGet(Protocol[_KT_contra, _VT_co]): # type: ignore[misc] # Covariant type as parameter
173+
class SupportsGet(Protocol[_KT_contra, _VT_co]): # type: ignore[misc] # ty:ignore[invalid-protocol] # Covariant type as parameter
174174
@overload
175175
def get(self, key: _KT_contra, /) -> _VT_co | None: ...
176176
@overload
@@ -189,7 +189,7 @@ class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
189189
def keys(self) -> Iterable[_KT]: ...
190190
def __getitem__(self, key: _KT, /) -> _VT_co: ...
191191

192-
class SupportsKeysAndGet(Protocol[_KT, _VT_co]): # type: ignore[misc] # Covariant type as parameter
192+
class SupportsKeysAndGet(Protocol[_KT, _VT_co]): # type: ignore[misc] # ty:ignore[invalid-protocol] # Covariant type as parameter
193193
def keys(self) -> Iterable[_KT]: ...
194194

195195
@overload

‎stdlib/pathlib/__init__.pyi‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import sys
2-
import types
32
from _typeshed import (
43
OpenBinaryMode,
54
OpenBinaryModeReading,
@@ -14,7 +13,7 @@ from _typeshed import (
1413
from collections.abc import Callable, Generator, Iterator, Sequence
1514
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
1615
from os import PathLike, stat_result
17-
from types import GenericAlias, TracebackType
16+
from types import GenericAlias, ModuleType, TracebackType
1817
from typing import IO, Any, BinaryIO, ClassVar, Literal, TypeVar, overload
1918
from typing_extensions import Never, Self, deprecated
2019

@@ -56,7 +55,7 @@ class PurePath(PathLike[str]):
5655
else:
5756
__slots__ = ("_drv", "_root", "_parts", "_str", "_hash", "_pparts", "_cached_cparts")
5857
if sys.version_info >= (3, 13):
59-
parser: ClassVar[types.ModuleType]
58+
parser: ClassVar[ModuleType]
6059
def full_match(self, pattern: StrPath, *, case_sensitive: bool | None = None) -> bool: ...
6160

6261
@property

‎tests/ty_test.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import argparse
77
import subprocess
8-
import tempfile
98
from pathlib import Path
109

1110
from ts_utils.paths import STDLIB_PATH, STUBS_PATH, TS_BASE_PATH
@@ -50,9 +49,16 @@ def main() -> int:
5049
if not files:
5150
print("No stubs to check with ty.", flush=True)
5251
return 0
52+
# Per-file overrides need typeshed as the project root. Exclude it from module
53+
# search roots so ty resolves `builtins.pyi` as part of the custom typeshed,
54+
# rather than as a project source.
5355
command = [
5456
"ty",
5557
"check",
58+
"--project",
59+
str(TS_BASE_PATH),
60+
"--config",
61+
"environment.root = []",
5662
"--config-file",
5763
str(TS_BASE_PATH / "ty.toml"),
5864
"--typeshed",
@@ -74,11 +80,7 @@ def main() -> int:
7480
command.extend(map(str, files))
7581

7682
print(f"Checking {len(files)} stubs with ty ({args.python_version}, {args.platform})...", flush=True)
77-
# The custom typeshed cannot also be the project root: ty would treat builtins.pyi
78-
# as project source and panic while constructing its builtins model.
79-
with tempfile.TemporaryDirectory() as project:
80-
command[2:2] = ("--project", project)
81-
return subprocess.run(command, check=False).returncode
83+
return subprocess.run(command, check=False).returncode
8284

8385

8486
if __name__ == "__main__":

‎ty.toml‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,37 @@ deprecated = "ignore"
1818
invalid-attribute-override = "ignore"
1919
invalid-method-override = "ignore"
2020
override-of-final-method = "ignore"
21+
# Some `__init__` self annotations retain class-scoped type variables for mypy
22+
# compatibility (https://github.com/python/typeshed/pull/11780). Disable ty's
23+
# check; Pyright checks the stubs it covers, with targeted ignores where needed.
24+
invalid-init-type-variable = "ignore"
25+
26+
# Several existing annotations conflict with ty's variance checks.
27+
# Ignore these errors temporarily in the affected files until they can be
28+
# handled individually.
29+
[[overrides]]
30+
include = [
31+
"stdlib/_collections_abc.pyi",
32+
"stdlib/builtins.pyi",
33+
"stdlib/email/_policybase.pyi",
34+
"stdlib/email/message.pyi",
35+
"stdlib/functools.pyi",
36+
"stdlib/mailbox.pyi",
37+
"stdlib/types.pyi",
38+
"stdlib/typing.pyi",
39+
"stubs/WebOb/webob/dec.pyi",
40+
"stubs/boltons/boltons/tbutils.pyi",
41+
"stubs/psycopg2/psycopg2/_range.pyi",
42+
"stubs/tensorflow/tensorflow/data/__init__.pyi",
43+
]
44+
45+
[overrides.rules]
46+
invalid-generic-class = "ignore"
47+
48+
# `types.pyi` already has an inline `invalid-generic-class` ignore; suppress
49+
# `unused-ignore-comment` while the rule is ignored for the whole file.
50+
[[overrides]]
51+
include = ["stdlib/types.pyi"]
52+
53+
[overrides.rules]
54+
unused-ignore-comment = "ignore"

0 commit comments

Comments
 (0)