Skip to content

Commit cafb96a

Browse files
[ty] Sync vendored typeshed stubs (#20876)
Close and reopen this PR to trigger CI --------- Co-authored-by: typeshedbot <> Co-authored-by: David Peter <[email protected]>
1 parent 651f796 commit cafb96a

File tree

27 files changed

+486
-287
lines changed

27 files changed

+486
-287
lines changed

crates/ty_ide/src/completion.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,13 +1842,13 @@ C.<CURSOR>
18421842
__name__ :: str
18431843
__ne__ :: def __ne__(self, value: object, /) -> bool
18441844
__new__ :: def __new__(cls) -> Self@__new__
1845-
__or__ :: bound method <class 'C'>.__or__(value: Any, /) -> UnionType
1845+
__or__ :: bound method <class 'C'>.__or__[Self](value: Any, /) -> UnionType | Self@__or__
18461846
__prepare__ :: bound method <class 'Meta'>.__prepare__(name: str, bases: tuple[type, ...], /, **kwds: Any) -> MutableMapping[str, object]
18471847
__qualname__ :: str
18481848
__reduce__ :: def __reduce__(self) -> str | tuple[Any, ...]
18491849
__reduce_ex__ :: def __reduce_ex__(self, protocol: SupportsIndex, /) -> str | tuple[Any, ...]
18501850
__repr__ :: def __repr__(self) -> str
1851-
__ror__ :: bound method <class 'C'>.__ror__(value: Any, /) -> UnionType
1851+
__ror__ :: bound method <class 'C'>.__ror__[Self](value: Any, /) -> UnionType | Self@__ror__
18521852
__setattr__ :: def __setattr__(self, name: str, value: Any, /) -> None
18531853
__sizeof__ :: def __sizeof__(self) -> int
18541854
__str__ :: def __str__(self) -> str
@@ -1910,13 +1910,13 @@ Meta.<CURSOR>
19101910
__mro__ :: tuple[<class 'Meta'>, <class 'type'>, <class 'object'>]
19111911
__name__ :: str
19121912
__ne__ :: def __ne__(self, value: object, /) -> bool
1913-
__or__ :: def __or__(self, value: Any, /) -> UnionType
1913+
__or__ :: def __or__[Self](self: Self@__or__, value: Any, /) -> UnionType | Self@__or__
19141914
__prepare__ :: bound method <class 'Meta'>.__prepare__(name: str, bases: tuple[type, ...], /, **kwds: Any) -> MutableMapping[str, object]
19151915
__qualname__ :: str
19161916
__reduce__ :: def __reduce__(self) -> str | tuple[Any, ...]
19171917
__reduce_ex__ :: def __reduce_ex__(self, protocol: SupportsIndex, /) -> str | tuple[Any, ...]
19181918
__repr__ :: def __repr__(self) -> str
1919-
__ror__ :: def __ror__(self, value: Any, /) -> UnionType
1919+
__ror__ :: def __ror__[Self](self: Self@__ror__, value: Any, /) -> UnionType | Self@__ror__
19201920
__setattr__ :: def __setattr__(self, name: str, value: Any, /) -> None
19211921
__sizeof__ :: def __sizeof__(self) -> int
19221922
__str__ :: def __str__(self) -> str
@@ -2019,13 +2019,13 @@ Quux.<CURSOR>
20192019
__name__ :: str
20202020
__ne__ :: def __ne__(self, value: object, /) -> bool
20212021
__new__ :: def __new__(cls) -> Self@__new__
2022-
__or__ :: bound method <class 'Quux'>.__or__(value: Any, /) -> UnionType
2022+
__or__ :: bound method <class 'Quux'>.__or__[Self](value: Any, /) -> UnionType | Self@__or__
20232023
__prepare__ :: bound method <class 'type'>.__prepare__(name: str, bases: tuple[type, ...], /, **kwds: Any) -> MutableMapping[str, object]
20242024
__qualname__ :: str
20252025
__reduce__ :: def __reduce__(self) -> str | tuple[Any, ...]
20262026
__reduce_ex__ :: def __reduce_ex__(self, protocol: SupportsIndex, /) -> str | tuple[Any, ...]
20272027
__repr__ :: def __repr__(self) -> str
2028-
__ror__ :: bound method <class 'Quux'>.__ror__(value: Any, /) -> UnionType
2028+
__ror__ :: bound method <class 'Quux'>.__ror__[Self](value: Any, /) -> UnionType | Self@__ror__
20292029
__setattr__ :: def __setattr__(self, name: str, value: Any, /) -> None
20302030
__sizeof__ :: def __sizeof__(self) -> int
20312031
__str__ :: def __str__(self) -> str
@@ -2096,14 +2096,14 @@ Answer.<CURSOR>
20962096
__name__ :: str
20972097
__ne__ :: def __ne__(self, value: object, /) -> bool
20982098
__new__ :: def __new__(cls, value: object) -> Self@__new__
2099-
__or__ :: bound method <class 'Answer'>.__or__(value: Any, /) -> UnionType
2099+
__or__ :: bound method <class 'Answer'>.__or__[Self](value: Any, /) -> UnionType | Self@__or__
21002100
__order__ :: str
21012101
__prepare__ :: bound method <class 'EnumMeta'>.__prepare__(cls: str, bases: tuple[type, ...], **kwds: Any) -> _EnumDict
21022102
__qualname__ :: str
21032103
__reduce__ :: def __reduce__(self) -> str | tuple[Any, ...]
21042104
__repr__ :: def __repr__(self) -> str
21052105
__reversed__ :: bound method <class 'Answer'>.__reversed__[_EnumMemberT]() -> Iterator[_EnumMemberT@__reversed__]
2106-
__ror__ :: bound method <class 'Answer'>.__ror__(value: Any, /) -> UnionType
2106+
__ror__ :: bound method <class 'Answer'>.__ror__[Self](value: Any, /) -> UnionType | Self@__ror__
21072107
__setattr__ :: def __setattr__(self, name: str, value: Any, /) -> None
21082108
__sizeof__ :: def __sizeof__(self) -> int
21092109
__str__ :: def __str__(self) -> str

crates/ty_ide/src/goto_type_definition.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ mod tests {
199199

200200
assert_snapshot!(test.goto_type_definition(), @r#"
201201
info[goto-type-definition]: Type definition
202-
--> stdlib/builtins.pyi:911:7
202+
--> stdlib/builtins.pyi:913:7
203203
|
204-
910 | @disjoint_base
205-
911 | class str(Sequence[str]):
204+
912 | @disjoint_base
205+
913 | class str(Sequence[str]):
206206
| ^^^
207-
912 | """str(object='') -> str
208-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
207+
914 | """str(object='') -> str
208+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
209209
|
210210
info: Source
211211
--> main.py:4:1
@@ -227,13 +227,13 @@ mod tests {
227227

228228
assert_snapshot!(test.goto_type_definition(), @r#"
229229
info[goto-type-definition]: Type definition
230-
--> stdlib/builtins.pyi:911:7
230+
--> stdlib/builtins.pyi:913:7
231231
|
232-
910 | @disjoint_base
233-
911 | class str(Sequence[str]):
232+
912 | @disjoint_base
233+
913 | class str(Sequence[str]):
234234
| ^^^
235-
912 | """str(object='') -> str
236-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
235+
914 | """str(object='') -> str
236+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
237237
|
238238
info: Source
239239
--> main.py:2:10
@@ -324,13 +324,13 @@ mod tests {
324324

325325
assert_snapshot!(test.goto_type_definition(), @r#"
326326
info[goto-type-definition]: Type definition
327-
--> stdlib/builtins.pyi:911:7
327+
--> stdlib/builtins.pyi:913:7
328328
|
329-
910 | @disjoint_base
330-
911 | class str(Sequence[str]):
329+
912 | @disjoint_base
330+
913 | class str(Sequence[str]):
331331
| ^^^
332-
912 | """str(object='') -> str
333-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
332+
914 | """str(object='') -> str
333+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
334334
|
335335
info: Source
336336
--> main.py:4:6
@@ -358,13 +358,13 @@ mod tests {
358358
// is an int. Navigating to `str` would match pyright's behavior.
359359
assert_snapshot!(test.goto_type_definition(), @r#"
360360
info[goto-type-definition]: Type definition
361-
--> stdlib/builtins.pyi:344:7
361+
--> stdlib/builtins.pyi:346:7
362362
|
363-
343 | @disjoint_base
364-
344 | class int:
363+
345 | @disjoint_base
364+
346 | class int:
365365
| ^^^
366-
345 | """int([x]) -> integer
367-
346 | int(x, base=10) -> integer
366+
347 | """int([x]) -> integer
367+
348 | int(x, base=10) -> integer
368368
|
369369
info: Source
370370
--> main.py:4:6
@@ -391,13 +391,13 @@ f(**kwargs<CURSOR>)
391391

392392
assert_snapshot!(test.goto_type_definition(), @r#"
393393
info[goto-type-definition]: Type definition
394-
--> stdlib/builtins.pyi:2916:7
394+
--> stdlib/builtins.pyi:2918:7
395395
|
396-
2915 | @disjoint_base
397-
2916 | class dict(MutableMapping[_KT, _VT]):
396+
2917 | @disjoint_base
397+
2918 | class dict(MutableMapping[_KT, _VT]):
398398
| ^^^^
399-
2917 | """dict() -> new empty dictionary
400-
2918 | dict(mapping) -> new dictionary initialized from a mapping object's
399+
2919 | """dict() -> new empty dictionary
400+
2920 | dict(mapping) -> new dictionary initialized from a mapping object's
401401
|
402402
info: Source
403403
--> main.py:6:5
@@ -421,13 +421,13 @@ f(**kwargs<CURSOR>)
421421

422422
assert_snapshot!(test.goto_type_definition(), @r#"
423423
info[goto-type-definition]: Type definition
424-
--> stdlib/builtins.pyi:911:7
424+
--> stdlib/builtins.pyi:913:7
425425
|
426-
910 | @disjoint_base
427-
911 | class str(Sequence[str]):
426+
912 | @disjoint_base
427+
913 | class str(Sequence[str]):
428428
| ^^^
429-
912 | """str(object='') -> str
430-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
429+
914 | """str(object='') -> str
430+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
431431
|
432432
info: Source
433433
--> main.py:3:5
@@ -513,13 +513,13 @@ f(**kwargs<CURSOR>)
513513

514514
assert_snapshot!(test.goto_type_definition(), @r#"
515515
info[goto-type-definition]: Type definition
516-
--> stdlib/builtins.pyi:911:7
516+
--> stdlib/builtins.pyi:913:7
517517
|
518-
910 | @disjoint_base
519-
911 | class str(Sequence[str]):
518+
912 | @disjoint_base
519+
913 | class str(Sequence[str]):
520520
| ^^^
521-
912 | """str(object='') -> str
522-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
521+
914 | """str(object='') -> str
522+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
523523
|
524524
info: Source
525525
--> main.py:4:15
@@ -560,13 +560,13 @@ f(**kwargs<CURSOR>)
560560
|
561561
562562
info[goto-type-definition]: Type definition
563-
--> stdlib/builtins.pyi:911:7
563+
--> stdlib/builtins.pyi:913:7
564564
|
565-
910 | @disjoint_base
566-
911 | class str(Sequence[str]):
565+
912 | @disjoint_base
566+
913 | class str(Sequence[str]):
567567
| ^^^
568-
912 | """str(object='') -> str
569-
913 | str(bytes_or_buffer[, encoding[, errors]]) -> str
568+
914 | """str(object='') -> str
569+
915 | str(bytes_or_buffer[, encoding[, errors]]) -> str
570570
|
571571
info: Source
572572
--> main.py:3:5

crates/ty_python_semantic/resources/mdtest/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ All attribute access on literal `bytes` types is currently delegated to `builtin
21892189
```py
21902190
# revealed: bound method Literal[b"foo"].join(iterable_of_bytes: Iterable[@Todo(Support for `typing.TypeAlias`)], /) -> bytes
21912191
reveal_type(b"foo".join)
2192-
# revealed: bound method Literal[b"foo"].endswith(suffix: @Todo(Support for `typing.TypeAlias`) | tuple[@Todo(Support for `typing.TypeAlias`), ...], start: SupportsIndex | None = EllipsisType, end: SupportsIndex | None = EllipsisType, /) -> bool
2192+
# revealed: bound method Literal[b"foo"].endswith(suffix: @Todo(Support for `typing.TypeAlias`) | tuple[@Todo(Support for `typing.TypeAlias`), ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
21932193
reveal_type(b"foo".endswith)
21942194
```
21952195

crates/ty_python_semantic/resources/mdtest/binary/classes.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,27 @@ class B: ...
3030
# error: "Operator `|` is unsupported between objects of type `<class 'A'>` and `<class 'B'>`"
3131
reveal_type(A | B) # revealed: Unknown
3232
```
33+
34+
## Other binary operations resulting in `UnionType`
35+
36+
```toml
37+
[environment]
38+
python-version = "3.12"
39+
```
40+
41+
```py
42+
class A: ...
43+
class B: ...
44+
45+
def _(sub_a: type[A], sub_b: type[B]):
46+
reveal_type(A | sub_b) # revealed: UnionType
47+
reveal_type(sub_a | B) # revealed: UnionType
48+
reveal_type(sub_a | sub_b) # revealed: UnionType
49+
50+
class C[T]: ...
51+
class D[T]: ...
52+
53+
reveal_type(C | D) # revealed: UnionType
54+
55+
reveal_type(C[int] | D[str]) # revealed: UnionType
56+
```

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static_assert(is_assignable_to(TypeOf[property.__set__], Callable))
651651
reveal_type(MyClass.my_property.__set__)
652652
static_assert(is_assignable_to(TypeOf[MyClass.my_property.__set__], Callable))
653653

654-
# revealed: def startswith(self, prefix: str | tuple[str, ...], start: SupportsIndex | None = EllipsisType, end: SupportsIndex | None = EllipsisType, /) -> bool
654+
# revealed: def startswith(self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
655655
reveal_type(str.startswith)
656656
static_assert(is_assignable_to(TypeOf[str.startswith], Callable))
657657

@@ -689,7 +689,7 @@ def _(
689689
# revealed: (obj: type) -> None
690690
reveal_type(e)
691691

692-
# revealed: (fget: ((Any, /) -> Any) | None = EllipsisType, fset: ((Any, Any, /) -> None) | None = EllipsisType, fdel: ((Any, /) -> None) | None = EllipsisType, doc: str | None = EllipsisType) -> property
692+
# revealed: (fget: ((Any, /) -> Any) | None = None, fset: ((Any, Any, /) -> None) | None = None, fdel: ((Any, /) -> None) | None = None, doc: str | None = None) -> property
693693
reveal_type(f)
694694

695695
# revealed: Overload[(self: property, instance: None, owner: type, /) -> Unknown, (self: property, instance: object, owner: type | None = None, /) -> Unknown]
@@ -707,7 +707,7 @@ def _(
707707
# revealed: (instance: object, value: object, /) -> Unknown
708708
reveal_type(j)
709709

710-
# revealed: (self, prefix: str | tuple[str, ...], start: SupportsIndex | None = EllipsisType, end: SupportsIndex | None = EllipsisType, /) -> bool
710+
# revealed: (self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
711711
reveal_type(k)
712712

713713
# revealed: (prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool

crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno…_-_Basic_(f15db7dc447d0795).snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ error[invalid-await]: `Literal[1]` is not awaitable
2626
2 | await 1 # error: [invalid-await]
2727
| ^
2828
|
29-
::: stdlib/builtins.pyi:344:7
29+
::: stdlib/builtins.pyi:346:7
3030
|
31-
343 | @disjoint_base
32-
344 | class int:
31+
345 | @disjoint_base
32+
346 | class int:
3333
| --- type defined here
34-
345 | """int([x]) -> integer
35-
346 | int(x, base=10) -> integer
34+
347 | """int([x]) -> integer
35+
348 | int(x, base=10) -> integer
3636
|
3737
info: `__await__` is missing
3838
info: rule `invalid-await` is enabled by default

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7957,6 +7957,21 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
79577957
)))
79587958
}
79597959

7960+
// Special-case `X | Y` with `X` and `Y` instances of `type` to produce a `types.UnionType` instance, in order to
7961+
// overwrite the typeshed return type for `type.__or__`, which would result in `types.UnionType | X`. We currently
7962+
// do this to avoid false positives when a legacy type alias like `IntOrStr = int | str` is later used in a type
7963+
// expression, because `types.UnionType` will result in a `@Todo` type, while `types.UnionType | <class 'int'>` does
7964+
// not.
7965+
//
7966+
// TODO: Remove this special case once we add support for legacy type aliases.
7967+
(
7968+
Type::ClassLiteral(..) | Type::SubclassOf(..) | Type::GenericAlias(..),
7969+
Type::ClassLiteral(..) | Type::SubclassOf(..) | Type::GenericAlias(..),
7970+
ast::Operator::BitOr,
7971+
) if Program::get(self.db()).python_version(self.db()) >= PythonVersion::PY310 => {
7972+
Some(KnownClass::UnionType.to_instance(self.db()))
7973+
}
7974+
79607975
// We've handled all of the special cases that we support for literals, so we need to
79617976
// fall back on looking for dunder methods on one of the operand types.
79627977
(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
91055c730ffcda6311654cf32d663858ece69bad
1+
d6f4a0f7102b1400a21742cf9b7ea93614e2b6ec

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ else:
136136
def writerows(self, rows: Iterable[Iterable[Any]]) -> None: ...
137137

138138
def writer(
139-
csvfile: SupportsWrite[str],
139+
fileobj: SupportsWrite[str],
140140
/,
141141
dialect: _DialectLike = "excel",
142142
*,
@@ -164,7 +164,7 @@ def writer(
164164
"""
165165

166166
def reader(
167-
csvfile: Iterable[str],
167+
iterable: Iterable[str],
168168
/,
169169
dialect: _DialectLike = "excel",
170170
*,
@@ -194,7 +194,8 @@ def reader(
194194

195195
def register_dialect(
196196
name: str,
197-
dialect: type[Dialect | csv.Dialect] = ...,
197+
/,
198+
dialect: type[Dialect | csv.Dialect] | str = "excel",
198199
*,
199200
delimiter: str = ",",
200201
quotechar: str | None = '"',

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class SourceLoader(_LoaderBasics):
251251
"""
252252

253253
def source_to_code(
254-
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: ReadableBuffer | StrPath
254+
self, data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive, path: bytes | StrPath
255255
) -> types.CodeType:
256256
"""Return the code object compiled from source.
257257
@@ -281,10 +281,10 @@ class FileLoader:
281281
def get_data(self, path: str) -> bytes:
282282
"""Return the data from path as raw bytes."""
283283

284-
def get_filename(self, name: str | None = None) -> str:
284+
def get_filename(self, fullname: str | None = None) -> str:
285285
"""Return the path to the source file as found by the finder."""
286286

287-
def load_module(self, name: str | None = None) -> types.ModuleType:
287+
def load_module(self, fullname: str | None = None) -> types.ModuleType:
288288
"""Load a module from a file.
289289
290290
This method is deprecated. Use exec_module() instead.
@@ -311,7 +311,7 @@ class SourceFileLoader(importlib.abc.FileLoader, FileLoader, importlib.abc.Sourc
311311
def source_to_code( # type: ignore[override] # incompatible with InspectLoader.source_to_code
312312
self,
313313
data: ReadableBuffer | str | _ast.Module | _ast.Expression | _ast.Interactive,
314-
path: ReadableBuffer | StrPath,
314+
path: bytes | StrPath,
315315
*,
316316
_optimize: int = -1,
317317
) -> types.CodeType:
@@ -335,7 +335,7 @@ class ExtensionFileLoader(FileLoader, _LoaderBasics, importlib.abc.ExecutionLoad
335335
"""
336336

337337
def __init__(self, name: str, path: str) -> None: ...
338-
def get_filename(self, name: str | None = None) -> str:
338+
def get_filename(self, fullname: str | None = None) -> str:
339339
"""Return the path to the source file as found by the finder."""
340340

341341
def get_source(self, fullname: str) -> None:

0 commit comments

Comments
 (0)