Improve and enforce type hints for imap (#92325)

This commit is contained in:
Jan Bouwhuis 2023-05-05 19:21:57 +02:00 committed by GitHub
parent e41a75f617
commit 53e533af6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -170,6 +170,7 @@ homeassistant.components.hyperion.*
homeassistant.components.ibeacon.*
homeassistant.components.image_processing.*
homeassistant.components.image_upload.*
homeassistant.components.imap.*
homeassistant.components.input_button.*
homeassistant.components.input_select.*
homeassistant.components.integration.*

View File

@ -108,9 +108,9 @@ class ImapMessage:
Will look for text/plain or use text/html if not found.
"""
message_text = None
message_html = None
message_untyped_text = None
message_text: str | None = None
message_html: str | None = None
message_untyped_text: str | None = None
for part in self.email_message.walk():
if part.get_content_type() == CONTENT_TYPE_TEXT_PLAIN:
@ -134,7 +134,7 @@ class ImapMessage:
if message_untyped_text is not None:
return message_untyped_text
return self.email_message.get_payload()
return str(self.email_message.get_payload())
class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
@ -231,7 +231,7 @@ class ImapDataUpdateCoordinator(DataUpdateCoordinator[int | None]):
_LOGGER.debug("Error while cleaning up imap connection")
self.imap_client = None
async def shutdown(self, *_) -> None:
async def shutdown(self, *_: Any) -> None:
"""Close resources."""
await self._cleanup(log_error=True)
@ -336,7 +336,7 @@ class ImapPushDataUpdateCoordinator(ImapDataUpdateCoordinator):
await self._cleanup()
await asyncio.sleep(BACKOFF_TIME)
async def shutdown(self, *_) -> None:
async def shutdown(self, *_: Any) -> None:
"""Close resources."""
if self._push_wait_task:
self._push_wait_task.cancel()

View File

@ -1462,6 +1462,16 @@ disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.imap.*]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
warn_return_any = true
warn_unreachable = true
[mypy-homeassistant.components.input_button.*]
check_untyped_defs = true
disallow_incomplete_defs = true