Generics and other type hint improvements (#45250)

This commit is contained in:
Ville Skyttä 2021-01-18 23:23:25 +02:00 committed by GitHub
parent 4928476abe
commit 94dbcc9d2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 45 deletions

View file

@ -571,7 +571,7 @@ class Context:
parent_id: Optional[str] = attr.ib(default=None)
id: str = attr.ib(factory=uuid_util.random_uuid_hex)
def as_dict(self) -> dict:
def as_dict(self) -> Dict[str, Optional[str]]:
"""Return a dictionary representation of the context."""
return {"id": self.id, "parent_id": self.parent_id, "user_id": self.user_id}
@ -612,7 +612,7 @@ class Event:
# The only event type that shares context are the TIME_CHANGED
return hash((self.event_type, self.context.id, self.time_fired))
def as_dict(self) -> Dict:
def as_dict(self) -> Dict[str, Any]:
"""Create a dict representation of this Event.
Async friendly.
@ -682,7 +682,7 @@ class EventBus:
def async_fire(
self,
event_type: str,
event_data: Optional[Dict] = None,
event_data: Optional[Dict[str, Any]] = None,
origin: EventOrigin = EventOrigin.local,
context: Optional[Context] = None,
time_fired: Optional[datetime.datetime] = None,
@ -844,7 +844,7 @@ class State:
self,
entity_id: str,
state: str,
attributes: Optional[Mapping] = None,
attributes: Optional[Mapping[str, Any]] = None,
last_changed: Optional[datetime.datetime] = None,
last_updated: Optional[datetime.datetime] = None,
context: Optional[Context] = None,
@ -1091,7 +1091,7 @@ class StateMachine:
self,
entity_id: str,
new_state: str,
attributes: Optional[Dict] = None,
attributes: Optional[Mapping[str, Any]] = None,
force_update: bool = False,
context: Optional[Context] = None,
) -> None:
@ -1140,7 +1140,7 @@ class StateMachine:
self,
entity_id: str,
new_state: str,
attributes: Optional[Dict] = None,
attributes: Optional[Mapping[str, Any]] = None,
force_update: bool = False,
context: Optional[Context] = None,
) -> None: