Fix implicit-return in twitter (#122931)

This commit is contained in:
epenet 2024-07-31 20:48:51 +02:00 committed by GitHub
parent c702ffa7dd
commit 9023d80d1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -129,10 +129,11 @@ class TwitterNotificationService(BaseNotificationService):
else:
_LOGGER.debug("Message posted: %s", resp.json())
def upload_media_then_callback(self, callback, media_path=None):
def upload_media_then_callback(self, callback, media_path=None) -> None:
"""Upload media."""
if not media_path:
return callback()
callback()
return
with open(media_path, "rb") as file:
total_bytes = os.path.getsize(media_path)
@ -141,7 +142,7 @@ class TwitterNotificationService(BaseNotificationService):
if 199 > resp.status_code < 300:
self.log_error_resp(resp)
return None
return
media_id = resp.json()["media_id"]
media_id = self.upload_media_chunked(file, total_bytes, media_id)
@ -149,10 +150,11 @@ class TwitterNotificationService(BaseNotificationService):
resp = self.upload_media_finalize(media_id)
if 199 > resp.status_code < 300:
self.log_error_resp(resp)
return None
return
if resp.json().get("processing_info") is None:
return callback(media_id)
callback(media_id)
return
self.check_status_until_done(media_id, callback)
@ -209,7 +211,7 @@ class TwitterNotificationService(BaseNotificationService):
"media/upload", {"command": "FINALIZE", "media_id": media_id}
)
def check_status_until_done(self, media_id, callback, *args):
def check_status_until_done(self, media_id, callback, *args) -> None:
"""Upload media, STATUS phase."""
resp = self.api.request(
"media/upload",
@ -223,7 +225,8 @@ class TwitterNotificationService(BaseNotificationService):
_LOGGER.debug("media processing %s status: %s", media_id, processing_info)
if processing_info["state"] in {"succeeded", "failed"}:
return callback(media_id)
callback(media_id)
return
check_after_secs = processing_info["check_after_secs"]
_LOGGER.debug(