mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 16:27:08 +00:00
Allow inheriting FrozenOrThawed
with custom init (#105624)
This commit is contained in:
parent
c318445a76
commit
22c3847c0e
@ -117,4 +117,5 @@ class FrozenOrThawed(type):
|
||||
return object.__new__(cls)
|
||||
return cls._dataclass(*_args, **kwargs)
|
||||
|
||||
cls.__init__ = cls._dataclass.__init__ # type: ignore[misc]
|
||||
cls.__new__ = __new__ # type: ignore[method-assign]
|
||||
|
@ -36,6 +36,24 @@
|
||||
# name: test_extending_entity_description.1
|
||||
"test_extending_entity_description.<locals>.FrozenEntityDescription(key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None, extra='foo')"
|
||||
# ---
|
||||
# name: test_extending_entity_description.10
|
||||
dict({
|
||||
'device_class': None,
|
||||
'entity_category': None,
|
||||
'entity_registry_enabled_default': True,
|
||||
'entity_registry_visible_default': True,
|
||||
'force_update': False,
|
||||
'has_entity_name': False,
|
||||
'icon': None,
|
||||
'key': 'blah',
|
||||
'name': 'name',
|
||||
'translation_key': None,
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_extending_entity_description.11
|
||||
"test_extending_entity_description.<locals>.CustomInitEntityDescription(key='blah', device_class=None, entity_category=None, entity_registry_enabled_default=True, entity_registry_visible_default=True, force_update=False, icon=None, has_entity_name=False, name='name', translation_key=None, unit_of_measurement=None)"
|
||||
# ---
|
||||
# name: test_extending_entity_description.2
|
||||
dict({
|
||||
'device_class': None,
|
||||
|
@ -1749,3 +1749,15 @@ def test_extending_entity_description(snapshot: SnapshotAssertion):
|
||||
key="blah", extra="foo", mixin="mixin", name="name"
|
||||
)
|
||||
assert repr(obj) == snapshot
|
||||
|
||||
# Try inheriting with custom init
|
||||
@dataclasses.dataclass
|
||||
class CustomInitEntityDescription(entity.EntityDescription):
|
||||
def __init__(self, extra, *args, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.extra: str = extra
|
||||
|
||||
obj = CustomInitEntityDescription(key="blah", extra="foo", name="name")
|
||||
assert obj == snapshot
|
||||
assert obj == CustomInitEntityDescription(key="blah", extra="foo", name="name")
|
||||
assert repr(obj) == snapshot
|
||||
|
Loading…
x
Reference in New Issue
Block a user