Skip to content

Commit 1be5918

Browse files
authored
Use _typeshed.IdentityFunction more consistently (#8063)
1 parent 033516d commit 1be5918

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

stdlib/functools.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
import types
3-
from _typeshed import Self, SupportsAllComparisons, SupportsItems
3+
from _typeshed import IdentityFunction, Self, SupportsAllComparisons, SupportsItems
44
from collections.abc import Callable, Hashable, Iterable, Sequence, Sized
55
from typing import Any, Generic, NamedTuple, TypeVar, overload
66
from typing_extensions import Literal, TypeAlias, final
@@ -68,7 +68,7 @@ WRAPPER_ASSIGNMENTS: tuple[
6868
WRAPPER_UPDATES: tuple[Literal["__dict__"]]
6969

7070
def update_wrapper(wrapper: _T, wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> _T: ...
71-
def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> Callable[[_T], _T]: ...
71+
def wraps(wrapped: _AnyCallable, assigned: Sequence[str] = ..., updated: Sequence[str] = ...) -> IdentityFunction: ...
7272
def total_ordering(cls: type[_T]) -> type[_T]: ...
7373
def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsAllComparisons]: ...
7474

stdlib/typing.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import collections # Needed by aliases like DefaultDict, see mypy issue 2986
22
import sys
3-
from _typeshed import ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem
3+
from _typeshed import IdentityFunction, ReadableBuffer, Self as TypeshedSelf, SupportsKeysAndGetItem
44
from abc import ABCMeta, abstractmethod
55
from types import BuiltinFunctionType, CodeType, FrameType, FunctionType, MethodType, ModuleType, TracebackType
66
from typing_extensions import Literal as _Literal, ParamSpec as _ParamSpec, final as _final
@@ -874,7 +874,7 @@ if sys.version_info >= (3, 11):
874874
kw_only_default: bool = ...,
875875
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = ...,
876876
**kwargs: Any,
877-
) -> Callable[[_T], _T]: ...
877+
) -> IdentityFunction: ...
878878

879879
# Type constructors
880880

stdlib/typing_extensions.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import abc
22
import sys
3-
from _typeshed import Self as TypeshedSelf # see #6932 for why the alias cannot have a leading underscore
3+
from _typeshed import IdentityFunction, Self as TypeshedSelf # see #6932 for why the Self alias cannot have a leading underscore
44
from typing import ( # noqa: Y022,Y027,Y039
55
TYPE_CHECKING as TYPE_CHECKING,
66
Any,
@@ -232,4 +232,4 @@ else:
232232
kw_only_default: bool = ...,
233233
field_specifiers: tuple[type[Any] | Callable[..., Any], ...] = ...,
234234
**kwargs: object,
235-
) -> Callable[[_T], _T]: ...
235+
) -> IdentityFunction: ...

stubs/mypy-extensions/mypy_extensions.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import abc
2-
from _typeshed import Self
3-
from collections.abc import Callable, ItemsView, KeysView, Mapping, ValuesView
2+
from _typeshed import IdentityFunction, Self
3+
from collections.abc import ItemsView, KeysView, Mapping, ValuesView
44
from typing import Any, Generic, TypeVar, overload
55

66
_T = TypeVar("_T")
@@ -54,6 +54,6 @@ class NoReturn: ...
5454
# a class decorator, but mypy does not support type[_T] for abstract
5555
# classes until this issue is resolved, https://github.com/python/mypy/issues/4717.
5656
def trait(cls: _T) -> _T: ...
57-
def mypyc_attr(*attrs: str, **kwattrs: object) -> Callable[[_T], _T]: ...
57+
def mypyc_attr(*attrs: str, **kwattrs: object) -> IdentityFunction: ...
5858

5959
class FlexibleAlias(Generic[_T, _U]): ...

stubs/six/six/__init__.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from __future__ import print_function
33
import builtins
44
import types
55
import unittest
6+
from _typeshed import IdentityFunction
67
from builtins import next as next
78
from collections.abc import Callable, ItemsView, Iterable, Iterator as _Iterator, KeysView, Mapping, ValuesView
89
from functools import wraps as wraps
@@ -83,7 +84,7 @@ def raise_from(value: BaseException | type[BaseException], from_value: BaseExcep
8384
print_ = print
8485

8586
def with_metaclass(meta: type, *bases: type) -> type: ...
86-
def add_metaclass(metaclass: type) -> Callable[[_T], _T]: ...
87+
def add_metaclass(metaclass: type) -> IdentityFunction: ...
8788
def ensure_binary(s: bytes | str, encoding: str = ..., errors: str = ...) -> bytes: ...
8889
def ensure_str(s: bytes | str, encoding: str = ..., errors: str = ...) -> str: ...
8990
def ensure_text(s: bytes | str, encoding: str = ..., errors: str = ...) -> str: ...

0 commit comments

Comments
 (0)