[ty] Sync vendored typeshed stubs (#21466)
Co-authored-by: typeshedbot <> Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
committed by
GitHub
parent
29acc1e860
commit
efa2b5167f
@@ -197,3 +197,9 @@ isinstance("", t.ClassVar) # error: [invalid-argument-type]
|
||||
isinstance("", t.Final) # error: [invalid-argument-type]
|
||||
isinstance("", t.Any) # error: [invalid-argument-type]
|
||||
```
|
||||
|
||||
## The builtin `NotImplemented` constant is not callable
|
||||
|
||||
```py
|
||||
NotImplemented() # error: [call-non-callable]
|
||||
```
|
||||
|
||||
@@ -466,11 +466,23 @@ def f(cond: bool) -> int:
|
||||
return "hello" if cond else NotImplemented
|
||||
```
|
||||
|
||||
`NotImplemented` is only special-cased for return types (mirroring the way the interpreter applies
|
||||
special casing for the symbol at runtime). It is not generally considered assignable to every other
|
||||
type:
|
||||
|
||||
```py
|
||||
# Other type checkers do not emit an error here,
|
||||
# but this is likely not a deliberate feature they've implemented;
|
||||
# it's probably because `NotImplementedType` inherits from `Any`
|
||||
# according to typeshed. We override typeshed's incorrect MRO
|
||||
# for more precise type inference.
|
||||
x: int = NotImplemented # error: [invalid-assignment]
|
||||
```
|
||||
|
||||
### Python 3.10+
|
||||
|
||||
Unlike Ellipsis, `_NotImplementedType` remains in `builtins.pyi` regardless of the Python version.
|
||||
Even if `builtins._NotImplementedType` is fully replaced by `types.NotImplementedType` in the
|
||||
future, it should still work as expected.
|
||||
We correctly understand the semantics of `NotImplemented` on all Python versions, even though the
|
||||
class `types.NotImplementedType` is only exposed in the `types` module on Python 3.10+.
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
|
||||
@@ -717,3 +717,17 @@ class F[T](F(), F): ... # error: [cyclic-class-definition]
|
||||
reveal_type(F.__class__) # revealed: type[Unknown]
|
||||
reveal_mro(F) # revealed: (<class 'F[Unknown]'>, Unknown, <class 'object'>)
|
||||
```
|
||||
|
||||
## `builtins.NotImplemented`
|
||||
|
||||
Typeshed tells us that `NotImplementedType` inherits from `Any`, but that causes more problems for
|
||||
us than it fixes. We override typeshed here so that we understand `NotImplementedType` as inheriting
|
||||
directly from `object` (as it does at runtime).
|
||||
|
||||
```py
|
||||
import types
|
||||
from ty_extensions import reveal_mro
|
||||
|
||||
reveal_mro(types.NotImplementedType) # revealed: (<class 'NotImplementedType'>, <class 'object'>)
|
||||
reveal_mro(type(NotImplemented)) # revealed: (<class 'NotImplementedType'>, <class 'object'>)
|
||||
```
|
||||
|
||||
@@ -26,13 +26,13 @@ error[invalid-await]: `Literal[1]` is not awaitable
|
||||
2 | await 1 # error: [invalid-await]
|
||||
| ^
|
||||
|
|
||||
::: stdlib/builtins.pyi:346:7
|
||||
::: stdlib/builtins.pyi:348:7
|
||||
|
|
||||
345 | @disjoint_base
|
||||
346 | class int:
|
||||
347 | @disjoint_base
|
||||
348 | class int:
|
||||
| --- type defined here
|
||||
347 | """int([x]) -> integer
|
||||
348 | int(x, base=10) -> integer
|
||||
349 | """int([x]) -> integer
|
||||
350 | int(x, base=10) -> integer
|
||||
|
|
||||
info: `__await__` is missing
|
||||
info: rule `invalid-await` is enabled by default
|
||||
|
||||
Reference in New Issue
Block a user