mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 12:54:11 +08:00
[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:
committed by
PyTorch MergeBot
parent
3525b834f0
commit
7f65a20884
@ -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 = {}
|
||||
|
Reference in New Issue
Block a user