[1/N] Use "is" in python type comparison (#165037)

It generally recommended to use `is/is not` to compare types. Therefore this series of changes apply this suggestion in the code base, and it aims to finally enabling related linter checks.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/165037
Approved by: https://github.com/mlazos
This commit is contained in:
Yuanyuan Chen
2025-10-10 12:36:46 +00:00
committed by PyTorch MergeBot
parent 960b0d5f0d
commit 70925bdf82
37 changed files with 51 additions and 51 deletions

View File

@ -792,7 +792,7 @@ def _set_element(root_dict: STATE_DICT_TYPE, path: OBJ_PATH, value: Any) -> None
for i in range(1, len(path)):
prev_key = path[i - 1]
key = path[i]
def_val: Union[CONTAINER_TYPE, list[Any]] = {} if type(key) == str else []
def_val: Union[CONTAINER_TYPE, list[Any]] = {} if type(key) is str else []
if isinstance(cur_container, Mapping):
cur_container = cast(
@ -806,7 +806,7 @@ def _set_element(root_dict: STATE_DICT_TYPE, path: OBJ_PATH, value: Any) -> None
cur_container = cur_container[prev_key]
key = path[-1]
if type(key) == int:
if type(key) is int:
extend_list(cast(list[Any], cur_container), key)
cur_container[key] = value