From 9f48881ba80342b7388d728f428fb01697386142 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Thu, 28 Nov 2024 04:02:58 +0000 Subject: [PATCH] [BE]: Enable RUF013 ban implicit optional (#141706) Enables RUF013 rule to ban implicit Optional (from areas not already checked by mypy). Pull Request resolved: https://github.com/pytorch/pytorch/pull/141706 Approved by: https://github.com/ezyang --- .../cuda/mem_eff_attention/kernels/generate_kernels.py | 2 +- pyproject.toml | 1 + torch/fx/proxy.py | 3 ++- torch/testing/_internal/common_device_type.py | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels/generate_kernels.py b/aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels/generate_kernels.py index d056eb22314..74df83f85f1 100644 --- a/aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels/generate_kernels.py +++ b/aten/src/ATen/native/transformers/cuda/mem_eff_attention/kernels/generate_kernels.py @@ -308,7 +308,7 @@ def write_decl_impl( family_name: str, impl_file: str, autogen_dir: Path, - disable_def: str = None, + disable_def: Optional[str] = None, ) -> None: cpp_file_header = """/* * Copyright (c) Meta Platforms, Inc. and affiliates. diff --git a/pyproject.toml b/pyproject.toml index c15594e54a7..81b2b2cbc19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -141,6 +141,7 @@ select = [ "Q004", # unnecessary escaped quote "RSE", "RUF008", # mutable dataclass default + "RUF013", # ban implicit optional "RUF015", # access first ele in constant time "RUF016", # type error non-integer index "RUF017", diff --git a/torch/fx/proxy.py b/torch/fx/proxy.py index ccbe0657547..7268a736333 100644 --- a/torch/fx/proxy.py +++ b/torch/fx/proxy.py @@ -215,7 +215,8 @@ class TracerBase: kwargs: Dict[str, Any], name: Optional[str] = None, type_expr: Optional[Any] = None, - proxy_factory_fn: Callable[[Node], "Proxy"] = None, + # fix noqa when updating bc tests + proxy_factory_fn: Callable[[Node], "Proxy"] = None, # noqa: RUF013 ): """ Create a Node from the given arguments, then return the Node diff --git a/torch/testing/_internal/common_device_type.py b/torch/testing/_internal/common_device_type.py index 7309dd51843..58a7f429dba 100644 --- a/torch/testing/_internal/common_device_type.py +++ b/torch/testing/_internal/common_device_type.py @@ -1846,7 +1846,7 @@ def skipCUDAIfNotMiopenSuggestNHWC(fn): # Skips a test for specified CUDA versions, given in the form of a list of [major, minor]s. -def skipCUDAVersionIn(versions: List[Tuple[int, int]] = None): +def skipCUDAVersionIn(versions: Optional[List[Tuple[int, int]]] = None): def dec_fn(fn): @wraps(fn) def wrap_fn(self, *args, **kwargs): @@ -1864,7 +1864,7 @@ def skipCUDAVersionIn(versions: List[Tuple[int, int]] = None): # Skips a test for CUDA versions less than specified, given in the form of [major, minor]. -def skipCUDAIfVersionLessThan(versions: Tuple[int, int] = None): +def skipCUDAIfVersionLessThan(versions: Optional[Tuple[int, int]] = None): def dec_fn(fn): @wraps(fn) def wrap_fn(self, *args, **kwargs):