mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[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:
committed by
PyTorch MergeBot
parent
960b0d5f0d
commit
70925bdf82
@ -891,7 +891,7 @@ class TypedStorage:
|
||||
def _new_wrapped_storage(self, untyped_storage) -> Self:
|
||||
assert type(untyped_storage) == torch.UntypedStorage
|
||||
|
||||
if type(self) == TypedStorage:
|
||||
if type(self) is TypedStorage:
|
||||
return cast(
|
||||
Self,
|
||||
TypedStorage(
|
||||
@ -913,7 +913,7 @@ class TypedStorage:
|
||||
return 0
|
||||
|
||||
else:
|
||||
if type(idx) != int:
|
||||
if type(idx) is not int:
|
||||
raise TypeError(f"can't index a {type(self)} with {type(idx)}")
|
||||
if is_stop:
|
||||
if (idx > self._size()) or (idx < -self._size()):
|
||||
@ -1513,7 +1513,7 @@ class _LegacyStorageMeta(type):
|
||||
dtype: torch.dtype
|
||||
|
||||
def __instancecheck__(cls, instance):
|
||||
if type(instance) == TypedStorage:
|
||||
if type(instance) is TypedStorage:
|
||||
cls_device = _get_device_from_module(cls.__module__)
|
||||
return (cls_device == instance.device.type) and (
|
||||
cls.dtype == instance.dtype
|
||||
|
||||
Reference in New Issue
Block a user