[BE]: Enable ruff SLOT checks (#146276)

This enables a check that which a class which only inherits from immutable classes like str, tuple, and NamedTuple, also defined `__slots__` so they don't allocate memory unnecessarily. This also ensure contributors think about how they define their classes with subclass NamedTuples and str, of which we have many in our codebase

Pull Request resolved: https://github.com/pytorch/pytorch/pull/146276
Approved by: https://github.com/aorenste
This commit is contained in:
Aaron Gokaslan
2025-02-04 19:18:21 +00:00
committed by PyTorch MergeBot
parent 3525b834f0
commit 7f65a20884
16 changed files with 32 additions and 7 deletions

View File

@ -139,6 +139,8 @@ def seq(a, b):
class isin:
__slots__ = ()
def __contains__(self, item):
for x in self:
if seq(item, x):
@ -153,11 +155,11 @@ class isin:
class llist(isin, list):
pass
__slots__ = ()
class ltuple(isin, tuple):
pass
__slots__ = ()
empty_dict = {}