From d61db732dab3bbc655f87c1022d247337f6100c8 Mon Sep 17 00:00:00 2001 From: Sid <27780930+autinerd@users.noreply.github.com> Date: Wed, 10 Apr 2024 06:57:27 +0200 Subject: [PATCH] Enable Ruff SLOT rules (#115043) --- homeassistant/helpers/template.py | 2 ++ homeassistant/util/event_type.py | 2 ++ pyproject.toml | 1 + tests/components/bluetooth/test_wrappers.py | 2 +- tests/helpers/test_config_validation.py | 2 +- tests/helpers/test_template.py | 2 +- tests/util/test_json.py | 2 +- 7 files changed, 9 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 501dd21d416..d344a473494 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -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: diff --git a/homeassistant/util/event_type.py b/homeassistant/util/event_type.py index e96d45c80a3..509a35d33ae 100644 --- a/homeassistant/util/event_type.py +++ b/homeassistant/util/event_type.py @@ -18,3 +18,5 @@ class EventType(str, Generic[_DataT]): At runtime this is a generic subclass of str. """ + + __slots__ = () diff --git a/pyproject.toml b/pyproject.toml index bda0ee4f85f..9ea03a63ff8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/components/bluetooth/test_wrappers.py b/tests/components/bluetooth/test_wrappers.py index 0630d671038..c14fb8a58c1 100644 --- a/tests/components/bluetooth/test_wrappers.py +++ b/tests/components/bluetooth/test_wrappers.py @@ -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) diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index 9816dc38189..5e9fcd9d661 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -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 diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 87279ef707b..fe152ac0d56 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -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 = { diff --git a/tests/util/test_json.py b/tests/util/test_json.py index b4a52cb4b41..3eccb524538 100644 --- a/tests/util/test_json.py +++ b/tests/util/test_json.py @@ -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