mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-16 21:38:11 +00:00
[ty] Sync vendored typeshed stubs (#20876)
Close and reopen this PR to trigger CI --------- Co-authored-by: typeshedbot <> Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
parent
651f7963a7
commit
cafb96aa7a
27 changed files with 487 additions and 288 deletions
|
@ -2189,7 +2189,7 @@ All attribute access on literal `bytes` types is currently delegated to `builtin
|
|||
```py
|
||||
# revealed: bound method Literal[b"foo"].join(iterable_of_bytes: Iterable[@Todo(Support for `typing.TypeAlias`)], /) -> bytes
|
||||
reveal_type(b"foo".join)
|
||||
# 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
|
||||
# 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
|
||||
reveal_type(b"foo".endswith)
|
||||
```
|
||||
|
||||
|
|
|
@ -30,3 +30,27 @@ class B: ...
|
|||
# error: "Operator `|` is unsupported between objects of type `<class 'A'>` and `<class 'B'>`"
|
||||
reveal_type(A | B) # revealed: Unknown
|
||||
```
|
||||
|
||||
## Other binary operations resulting in `UnionType`
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
python-version = "3.12"
|
||||
```
|
||||
|
||||
```py
|
||||
class A: ...
|
||||
class B: ...
|
||||
|
||||
def _(sub_a: type[A], sub_b: type[B]):
|
||||
reveal_type(A | sub_b) # revealed: UnionType
|
||||
reveal_type(sub_a | B) # revealed: UnionType
|
||||
reveal_type(sub_a | sub_b) # revealed: UnionType
|
||||
|
||||
class C[T]: ...
|
||||
class D[T]: ...
|
||||
|
||||
reveal_type(C | D) # revealed: UnionType
|
||||
|
||||
reveal_type(C[int] | D[str]) # revealed: UnionType
|
||||
```
|
||||
|
|
|
@ -651,7 +651,7 @@ static_assert(is_assignable_to(TypeOf[property.__set__], Callable))
|
|||
reveal_type(MyClass.my_property.__set__)
|
||||
static_assert(is_assignable_to(TypeOf[MyClass.my_property.__set__], Callable))
|
||||
|
||||
# revealed: def startswith(self, prefix: str | tuple[str, ...], start: SupportsIndex | None = EllipsisType, end: SupportsIndex | None = EllipsisType, /) -> bool
|
||||
# revealed: def startswith(self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
|
||||
reveal_type(str.startswith)
|
||||
static_assert(is_assignable_to(TypeOf[str.startswith], Callable))
|
||||
|
||||
|
@ -689,7 +689,7 @@ def _(
|
|||
# revealed: (obj: type) -> None
|
||||
reveal_type(e)
|
||||
|
||||
# revealed: (fget: ((Any, /) -> Any) | None = EllipsisType, fset: ((Any, Any, /) -> None) | None = EllipsisType, fdel: ((Any, /) -> None) | None = EllipsisType, doc: str | None = EllipsisType) -> property
|
||||
# revealed: (fget: ((Any, /) -> Any) | None = None, fset: ((Any, Any, /) -> None) | None = None, fdel: ((Any, /) -> None) | None = None, doc: str | None = None) -> property
|
||||
reveal_type(f)
|
||||
|
||||
# revealed: Overload[(self: property, instance: None, owner: type, /) -> Unknown, (self: property, instance: object, owner: type | None = None, /) -> Unknown]
|
||||
|
@ -707,7 +707,7 @@ def _(
|
|||
# revealed: (instance: object, value: object, /) -> Unknown
|
||||
reveal_type(j)
|
||||
|
||||
# revealed: (self, prefix: str | tuple[str, ...], start: SupportsIndex | None = EllipsisType, end: SupportsIndex | None = EllipsisType, /) -> bool
|
||||
# revealed: (self, prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
|
||||
reveal_type(k)
|
||||
|
||||
# revealed: (prefix: str | tuple[str, ...], start: SupportsIndex | None = None, end: SupportsIndex | None = None, /) -> bool
|
||||
|
|
|
@ -26,13 +26,13 @@ error[invalid-await]: `Literal[1]` is not awaitable
|
|||
2 | await 1 # error: [invalid-await]
|
||||
| ^
|
||||
|
|
||||
::: stdlib/builtins.pyi:344:7
|
||||
::: stdlib/builtins.pyi:346:7
|
||||
|
|
||||
343 | @disjoint_base
|
||||
344 | class int:
|
||||
345 | @disjoint_base
|
||||
346 | class int:
|
||||
| --- type defined here
|
||||
345 | """int([x]) -> integer
|
||||
346 | int(x, base=10) -> integer
|
||||
347 | """int([x]) -> integer
|
||||
348 | int(x, base=10) -> integer
|
||||
|
|
||||
info: `__await__` is missing
|
||||
info: rule `invalid-await` is enabled by default
|
||||
|
|
|
@ -7957,6 +7957,21 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
|||
)))
|
||||
}
|
||||
|
||||
// Special-case `X | Y` with `X` and `Y` instances of `type` to produce a `types.UnionType` instance, in order to
|
||||
// overwrite the typeshed return type for `type.__or__`, which would result in `types.UnionType | X`. We currently
|
||||
// do this to avoid false positives when a legacy type alias like `IntOrStr = int | str` is later used in a type
|
||||
// expression, because `types.UnionType` will result in a `@Todo` type, while `types.UnionType | <class 'int'>` does
|
||||
// not.
|
||||
//
|
||||
// TODO: Remove this special case once we add support for legacy type aliases.
|
||||
(
|
||||
Type::ClassLiteral(..) | Type::SubclassOf(..) | Type::GenericAlias(..),
|
||||
Type::ClassLiteral(..) | Type::SubclassOf(..) | Type::GenericAlias(..),
|
||||
ast::Operator::BitOr,
|
||||
) if Program::get(self.db()).python_version(self.db()) >= PythonVersion::PY310 => {
|
||||
Some(KnownClass::UnionType.to_instance(self.db()))
|
||||
}
|
||||
|
||||
// We've handled all of the special cases that we support for literals, so we need to
|
||||
// fall back on looking for dunder methods on one of the operand types.
|
||||
(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue