Enable Ruff SLOT rules (#115043)

This commit is contained in:
Sid 2024-04-10 06:57:27 +02:00 committed by GitHub
parent 0636ba340c
commit d61db732da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 9 additions and 4 deletions

View File

@ -305,6 +305,8 @@ def gen_result_wrapper(kls: type[dict | list | set]) -> type:
class TupleWrapper(tuple, ResultWrapper):
"""Wrap a tuple."""
__slots__ = ()
# This is all magic to be allowed to subclass a tuple.
def __new__(cls, value: tuple, *, render_result: str | None = None) -> Self:

View File

@ -18,3 +18,5 @@ class EventType(str, Generic[_DataT]):
At runtime this is a generic subclass of str.
"""
__slots__ = ()

View File

@ -664,6 +664,7 @@ select = [
"S608", # hardcoded-sql-expression
"S609", # unix-command-wildcard-injection
"SIM", # flake8-simplify
"SLOT", # flake8-slots
"T100", # Trace found: {name} used
"T20", # flake8-print
"TID251", # Banned imports

View File

@ -383,7 +383,7 @@ async def test_passing_subclassed_str_as_address(
_, cancel_hci0, cancel_hci1 = _generate_scanners_with_fake_devices(hass)
class SubclassedStr(str):
pass
__slots__ = ()
address = SubclassedStr("00:00:00:00:00:01")
client = bleak.BleakClient(address)

View File

@ -544,7 +544,7 @@ def test_string(hass: HomeAssistant) -> None:
# Test subclasses of str are returned
class MyString(str):
pass
__slots__ = ()
my_string = MyString("hello")
assert schema(my_string) is my_string

View File

@ -1270,7 +1270,7 @@ def test_to_json(hass: HomeAssistant) -> None:
# Test special case where substring class cannot be rendered
# See: https://github.com/ijl/orjson/issues/445
class MyStr(str):
pass
__slots__ = ()
expected_result = '{"mykey1":11.0,"mykey2":"myvalue2","mykey3":["opt3b","opt3a"]}'
test_dict = {

View File

@ -163,7 +163,7 @@ async def test_loading_derived_class():
"""Test loading data from classes derived from str."""
class MyStr(str):
pass
__slots__ = ()
class MyBytes(bytes):
pass