Skip to content

Commit d9473a2

Browse files
[ty] Sync vendored typeshed stubs (#20658)
--------- Co-authored-by: typeshedbot <> Co-authored-by: David Peter <mail@david-peter.de>
1 parent a422716 commit d9473a2

File tree

26 files changed

+1033
-988
lines changed

26 files changed

+1033
-988
lines changed

crates/ty_ide/src/goto_type_definition.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,13 @@ f(**kwargs<CURSOR>)
561561

562562
assert_snapshot!(test.goto_type_definition(), @r#"
563563
info[goto-type-definition]: Type definition
564-
--> stdlib/types.pyi:941:11
564+
--> stdlib/types.pyi:950:11
565565
|
566-
939 | if sys.version_info >= (3, 10):
567-
940 | @final
568-
941 | class NoneType:
566+
948 | if sys.version_info >= (3, 10):
567+
949 | @final
568+
950 | class NoneType:
569569
| ^^^^^^^^
570-
942 | """The type of the None singleton."""
570+
951 | """The type of the None singleton."""
571571
|
572572
info: Source
573573
--> main.py:3:5

crates/ty_python_semantic/resources/mdtest/call/replace.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ from datetime import time
1717
t = time(12, 0, 0)
1818
t = replace(t, minute=30)
1919

20-
reveal_type(t) # revealed: time
20+
# TODO: this should be `time`, once we support specialization of generic protocols
21+
reveal_type(t) # revealed: Unknown
2122
```
2223

2324
## The `__replace__` protocol
@@ -47,7 +48,8 @@ b = a.__replace__(x=3, y=4)
4748
reveal_type(b) # revealed: Point
4849

4950
b = replace(a, x=3, y=4)
50-
reveal_type(b) # revealed: Point
51+
# TODO: this should be `Point`, once we support specialization of generic protocols
52+
reveal_type(b) # revealed: Unknown
5153
```
5254

5355
A call to `replace` does not require all keyword arguments:
@@ -57,7 +59,8 @@ c = a.__replace__(y=4)
5759
reveal_type(c) # revealed: Point
5860

5961
d = replace(a, y=4)
60-
reveal_type(d) # revealed: Point
62+
# TODO: this should be `Point`, once we support specialization of generic protocols
63+
reveal_type(d) # revealed: Unknown
6164
```
6265

6366
Invalid calls to `__replace__` or `replace` will raise an error:

crates/ty_python_semantic/src/types/class.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,8 +4403,8 @@ impl KnownClass {
44034403
KnownClassDisplay { db, class: self }
44044404
}
44054405

4406-
/// Lookup a [`KnownClass`] in typeshed and return a [`Type`]
4407-
/// representing all possible instances of the class.
4406+
/// Lookup a [`KnownClass`] in typeshed and return a [`Type`] representing all possible instances of
4407+
/// the class. If this class is generic, this will use the default specialization.
44084408
///
44094409
/// If the class cannot be found in typeshed, a debug-level log message will be emitted stating this.
44104410
pub(crate) fn to_instance(self, db: &dyn Db) -> Type<'_> {
@@ -4414,6 +4414,14 @@ impl KnownClass {
44144414
.unwrap_or_else(Type::unknown)
44154415
}
44164416

4417+
/// Similar to [`KnownClass::to_instance`], but returns the Unknown-specialization where each type
4418+
/// parameter is specialized to `Unknown`.
4419+
pub(crate) fn to_instance_unknown(self, db: &dyn Db) -> Type<'_> {
4420+
self.try_to_class_literal(db)
4421+
.map(|literal| Type::instance(db, literal.unknown_specialization(db)))
4422+
.unwrap_or_else(Type::unknown)
4423+
}
4424+
44174425
/// Lookup a generic [`KnownClass`] in typeshed and return a [`Type`]
44184426
/// representing a specialization of that class.
44194427
///

crates/ty_python_semantic/src/types/infer/builder.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,16 +1923,18 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
19231923
//
19241924
// If type arguments are supplied to `(Async)Iterable`, `(Async)Iterator`,
19251925
// `(Async)Generator` or `(Async)GeneratorType` in the return annotation,
1926-
// we should iterate over the `yield` expressions and `return` statements in the function
1927-
// to check that they are consistent with the type arguments provided.
1926+
// we should iterate over the `yield` expressions and `return` statements
1927+
// in the function to check that they are consistent with the type arguments
1928+
// provided. Once we do this, the `.to_instance_unknown` call below should
1929+
// be replaced with `.to_specialized_instance`.
19281930
let inferred_return = if function.is_async {
19291931
KnownClass::AsyncGeneratorType
19301932
} else {
19311933
KnownClass::GeneratorType
19321934
};
19331935

19341936
if !inferred_return
1935-
.to_instance(self.db())
1937+
.to_instance_unknown(self.db())
19361938
.is_assignable_to(self.db(), expected_ty)
19371939
{
19381940
report_invalid_generator_function_return_type(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
47dbbd6c914a5190d54bc5bd498d1e6633d97db2
1+
91055c730ffcda6311654cf32d663858ece69bad

crates/ty_vendored/vendor/typeshed/stdlib/_collections_abc.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ Unit tests are in test_collections.
66
import sys
77
from abc import abstractmethod
88
from types import MappingProxyType
9-
from typing import ( # noqa: Y022,Y038,UP035
9+
from typing import ( # noqa: Y022,Y038,UP035,Y057
1010
AbstractSet as Set,
1111
AsyncGenerator as AsyncGenerator,
1212
AsyncIterable as AsyncIterable,
1313
AsyncIterator as AsyncIterator,
1414
Awaitable as Awaitable,
15+
ByteString as ByteString,
1516
Callable as Callable,
1617
ClassVar,
1718
Collection as Collection,
@@ -64,12 +65,8 @@ __all__ = [
6465
"ValuesView",
6566
"Sequence",
6667
"MutableSequence",
68+
"ByteString",
6769
]
68-
if sys.version_info < (3, 14):
69-
from typing import ByteString as ByteString # noqa: Y057,UP035
70-
71-
__all__ += ["ByteString"]
72-
7370
if sys.version_info >= (3, 12):
7471
__all__ += ["Buffer"]
7572

crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __import__(
2222
name: str,
2323
globals: Mapping[str, object] | None = None,
2424
locals: Mapping[str, object] | None = None,
25-
fromlist: Sequence[str] = (),
25+
fromlist: Sequence[str] | None = (),
2626
level: int = 0,
2727
) -> ModuleType:
2828
"""Import a module.

crates/ty_vendored/vendor/typeshed/stdlib/_tkinter.pyi

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,34 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
5757
@final
5858
class TkappType:
5959
# Please keep in sync with tkinter.Tk
60-
def adderrorinfo(self, msg, /): ...
60+
def adderrorinfo(self, msg: str, /): ...
6161
def call(self, command: Any, /, *args: Any) -> Any: ...
62-
def createcommand(self, name, func, /): ...
62+
def createcommand(self, name: str, func, /): ...
6363
if sys.platform != "win32":
64-
def createfilehandler(self, file, mask, func, /): ...
65-
def deletefilehandler(self, file, /): ...
64+
def createfilehandler(self, file, mask: int, func, /): ...
65+
def deletefilehandler(self, file, /) -> None: ...
6666

67-
def createtimerhandler(self, milliseconds, func, /): ...
68-
def deletecommand(self, name, /): ...
67+
def createtimerhandler(self, milliseconds: int, func, /): ...
68+
def deletecommand(self, name: str, /): ...
6969
def dooneevent(self, flags: int = 0, /): ...
7070
def eval(self, script: str, /) -> str: ...
71-
def evalfile(self, fileName, /): ...
72-
def exprboolean(self, s, /): ...
73-
def exprdouble(self, s, /): ...
74-
def exprlong(self, s, /): ...
75-
def exprstring(self, s, /): ...
76-
def getboolean(self, arg, /): ...
77-
def getdouble(self, arg, /): ...
78-
def getint(self, arg, /): ...
71+
def evalfile(self, fileName: str, /): ...
72+
def exprboolean(self, s: str, /): ...
73+
def exprdouble(self, s: str, /): ...
74+
def exprlong(self, s: str, /): ...
75+
def exprstring(self, s: str, /): ...
76+
def getboolean(self, arg, /) -> bool: ...
77+
def getdouble(self, arg, /) -> float: ...
78+
def getint(self, arg, /) -> int: ...
7979
def getvar(self, *args, **kwargs): ...
8080
def globalgetvar(self, *args, **kwargs): ...
8181
def globalsetvar(self, *args, **kwargs): ...
8282
def globalunsetvar(self, *args, **kwargs): ...
8383
def interpaddr(self) -> int: ...
8484
def loadtk(self) -> None: ...
85-
def mainloop(self, threshold: int = 0, /): ...
86-
def quit(self): ...
87-
def record(self, script, /): ...
85+
def mainloop(self, threshold: int = 0, /) -> None: ...
86+
def quit(self) -> None: ...
87+
def record(self, script: str, /): ...
8888
def setvar(self, *ags, **kwargs): ...
8989
if sys.version_info < (3, 11):
9090
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
@@ -93,7 +93,7 @@ class TkappType:
9393
def splitlist(self, arg, /): ...
9494
def unsetvar(self, *args, **kwargs): ...
9595
def wantobjects(self, *args, **kwargs): ...
96-
def willdispatch(self): ...
96+
def willdispatch(self) -> None: ...
9797
if sys.version_info >= (3, 12):
9898
def gettrace(self, /) -> _TkinterTraceFunc | None:
9999
"""Get the tracing function."""
@@ -164,10 +164,10 @@ else:
164164
if not None, then pass -use to wish
165165
"""
166166

167-
def getbusywaitinterval():
167+
def getbusywaitinterval() -> int:
168168
"""Return the current busy-wait interval between successive calls to Tcl_DoOneEvent in a threaded Python interpreter."""
169169

170-
def setbusywaitinterval(new_val, /):
170+
def setbusywaitinterval(new_val: int, /) -> None:
171171
"""Set the busy-wait interval in milliseconds between successive calls to Tcl_DoOneEvent in a threaded Python interpreter.
172172
173173
It should be set to a divisor of the maximum time between frames in an animation.

crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tools.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tools to analyze tasks running in asyncio programs."""
22

3+
import sys
34
from collections.abc import Iterable
45
from enum import Enum
56
from typing import NamedTuple, SupportsIndex, type_check_only
@@ -48,6 +49,15 @@ def build_async_tree(result: Iterable[_AwaitedInfo], task_emoji: str = "(T)", co
4849
"""
4950

5051
def build_task_table(result: Iterable[_AwaitedInfo]) -> list[list[int | str]]: ...
52+
53+
if sys.version_info >= (3, 14):
54+
def exit_with_permission_help_text() -> None:
55+
"""
56+
Prints a message pointing to platform-specific permission help text and exits the program.
57+
This function is called when a PermissionError is encountered while trying
58+
to attach to a process.
59+
"""
60+
5161
def display_awaited_by_tasks_table(pid: SupportsIndex) -> None:
5262
"""Build and print a table of all pending tasks under `pid`."""
5363

crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,7 +4153,14 @@ def open(
41534153
opener: _Opener | None = None,
41544154
) -> IO[Any]: ...
41554155
def ord(c: str | bytes | bytearray, /) -> int:
4156-
"""Return the Unicode code point for a one-character string."""
4156+
"""Return the ordinal value of a character.
4157+
4158+
If the argument is a one-character string, return the Unicode code
4159+
point of that character.
4160+
4161+
If the argument is a bytes or bytearray object of length 1, return its
4162+
single byte value.
4163+
"""
41574164

41584165
@type_check_only
41594166
class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ...
@@ -4451,7 +4458,7 @@ def __import__(
44514458
name: str,
44524459
globals: Mapping[str, object] | None = None,
44534460
locals: Mapping[str, object] | None = None,
4454-
fromlist: Sequence[str] = (),
4461+
fromlist: Sequence[str] | None = (),
44554462
level: int = 0,
44564463
) -> types.ModuleType:
44574464
"""Import a module.

0 commit comments

Comments
 (0)