Skip to content

Commit 43fb514

Browse files
isdannipytorchmergebot
authored andcommitted
[BE] Enable Ruff's Flake8 PYI001 (pytorch#112823)
Enable [unprefixed-type-param (PYI001)](https://docs.astral.sh/ruff/rules/unprefixed-type-param/#unprefixed-type-param-pyi001) Link: pytorch#110950 Pull Request resolved: pytorch#112823 Approved by: https://github.com/Skylion007
1 parent e2e5897 commit 43fb514

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

caffe2/python/context.pyi

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from typing import Optional, TypeVar, Type
22

3-
T = TypeVar('T')
3+
_T = TypeVar('_T')
44

55
class Managed:
66
@classmethod
7-
def current(cls: Type[T], value: Optional[T] = None, required: bool = True) -> T: ...
7+
def current(cls: Type[_T], value: Optional[_T] = None, required: bool = True) -> _T: ...
88

9-
def __call__(self, func: T) -> T: ...
9+
def __call__(self, func: _T) -> _T: ...
1010

11-
def __enter__(self: T) -> T: ...
11+
def __enter__(self: _T) -> _T: ...
1212

1313
class DefaultManaged(Managed): ...

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ ignore = [
4646
"G101", "G201", "G202",
4747
# these ignores are from RUFF perf; please fix!
4848
"PERF203", "PERF4",
49-
"PYI001", # these ignores are from PYI; please fix!
49+
# these ignores are from PYI; please fix!
5050
"PYI019",
5151
"PYI024",
5252
"PYI036",

torch/_C/_distributed_rpc.pyi

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ _DEFAULT_NUM_WORKER_THREADS: int
1515
_UNSET_RPC_TIMEOUT: float
1616
_DEFAULT_RPC_TIMEOUT_SEC: float
1717

18-
T = TypeVar("T")
18+
_T = TypeVar("_T")
1919

2020
class RpcBackendOptions:
2121
rpc_timeout: float
@@ -47,24 +47,24 @@ class RpcAgent:
4747
def get_debug_info(self) -> Dict[str, str]: ...
4848
def get_metrics(self) -> Dict[str, str]: ...
4949

50-
class PyRRef(Generic[T]):
51-
def __init__(self, value: T, type_hint: Any = None) -> None: ...
50+
class PyRRef(Generic[_T]):
51+
def __init__(self, value: _T, type_hint: Any = None) -> None: ...
5252
def is_owner(self) -> bool: ...
5353
def confirmed_by_owner(self) -> bool: ...
5454
def owner(self) -> WorkerInfo: ...
5555
def owner_name(self) -> str: ...
56-
def to_here(self, timeout: float = ...) -> T: ...
56+
def to_here(self, timeout: float = ...) -> _T: ...
5757
def local_value(self) -> Any: ...
5858
def rpc_sync(self, timeout: float = ...) -> Any: ...
5959
def rpc_async(self, timeout: float = ...) -> Any: ...
6060
def remote(self, timeout: float = ...) -> Any: ...
6161
def _serialize(self) -> Tuple: ...
6262
@staticmethod
6363
def _deserialize(tp: Tuple) -> PyRRef: ...
64-
def _get_type(self) -> Type[T]: ...
65-
def _get_future(self) -> Future[T]: ...
66-
def _get_profiling_future(self) -> Future[T]: ...
67-
def _set_profiling_future(self, profilingFuture: Future[T]): ...
64+
def _get_type(self) -> Type[_T]: ...
65+
def _get_future(self) -> Future[_T]: ...
66+
def _get_profiling_future(self) -> Future[_T]: ...
67+
def _set_profiling_future(self, profilingFuture: Future[_T]): ...
6868

6969
class _TensorPipeRpcBackendOptionsBase(RpcBackendOptions):
7070
num_worker_threads: int

torch/jit/_script.pyi

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type_trace_db: JitTypeTraceStore
6666

6767
# Defined in torch/csrc/jit/python/script_init.cpp
6868
ResolutionCallback: TypeAlias = Callable[[str], Callable[..., Any]]
69-
ClassVar = TypeVar("ClassVar", bound=type)
69+
_ClassVar = TypeVar("_ClassVar", bound=type)
7070

7171
def _reduce(cls) -> None: ...
7272

@@ -230,12 +230,12 @@ def script( # type: ignore[misc]
230230
) -> RecursiveScriptModule: ...
231231
@overload
232232
def script( # type: ignore[misc]
233-
obj: ClassVar,
233+
obj: _ClassVar,
234234
optimize: Optional[bool] = None,
235235
_frames_up: int = 0,
236236
_rcb: Optional[ResolutionCallback] = None,
237237
example_inputs: Union[List[Tuple], Dict[Callable, List[Tuple]], None] = None,
238-
) -> ClassVar: ...
238+
) -> _ClassVar: ...
239239
@overload
240240
def script( # type: ignore[misc]
241241
obj: Callable,

torch/nn/utils/rnn.pyi

+18-18
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PackedSequence_(NamedTuple):
2323

2424
def bind(optional: Any, fn: Any): ...
2525

26-
T = TypeVar("T")
26+
_T = TypeVar("_T")
2727

2828
class PackedSequence(PackedSequence_):
2929
def __new__(
@@ -33,39 +33,39 @@ class PackedSequence(PackedSequence_):
3333
sorted_indices: Optional[Tensor] = ...,
3434
unsorted_indices: Optional[Tensor] = ...,
3535
) -> Self: ...
36-
def pin_memory(self: T) -> T: ...
37-
def cuda(self: T, *args: Any, **kwargs: Any) -> T: ...
38-
def cpu(self: T) -> T: ...
39-
def double(self: T) -> T: ...
40-
def float(self: T) -> T: ...
41-
def half(self: T) -> T: ...
42-
def long(self: T) -> T: ...
43-
def int(self: T) -> T: ...
44-
def short(self: T) -> T: ...
45-
def char(self: T) -> T: ...
46-
def byte(self: T) -> T: ...
36+
def pin_memory(self: _T) -> _T: ...
37+
def cuda(self: _T, *args: Any, **kwargs: Any) -> _T: ...
38+
def cpu(self: _T) -> _T: ...
39+
def double(self: _T) -> _T: ...
40+
def float(self: _T) -> _T: ...
41+
def half(self: _T) -> _T: ...
42+
def long(self: _T) -> _T: ...
43+
def int(self: _T) -> _T: ...
44+
def short(self: _T) -> _T: ...
45+
def char(self: _T) -> _T: ...
46+
def byte(self: _T) -> _T: ...
4747
@overload
4848
def to(
49-
self: T,
49+
self: _T,
5050
dtype: _dtype,
5151
non_blocking: bool = False,
5252
copy: bool = False,
53-
) -> T: ...
53+
) -> _T: ...
5454
@overload
5555
def to(
56-
self: T,
56+
self: _T,
5757
device: Optional[Union[_device, str]] = None,
5858
dtype: Optional[_dtype] = None,
5959
non_blocking: bool = False,
6060
copy: bool = False,
61-
) -> T: ...
61+
) -> _T: ...
6262
@overload
6363
def to(
64-
self: T,
64+
self: _T,
6565
other: Tensor,
6666
non_blocking: bool = False,
6767
copy: bool = False,
68-
) -> T: ...
68+
) -> _T: ...
6969
@property
7070
def is_cuda(self) -> bool: ...
7171
def is_pinned(self) -> bool: ...

0 commit comments

Comments
 (0)