Use hasattr to check if any of required attribute is present

This commit is contained in:
Davide 2023-07-27 11:14:10 +02:00
parent ba6be8c3cd
commit d385cbba6f
No known key found for this signature in database
GPG key ID: D939AF7A93A9C178

View file

@ -75,14 +75,10 @@ class RealDownloadMiddleware(BaseDownloadMiddleware):
whose file attribute have either an URL or a file name.
"""
if super().is_download_response(response):
try:
return response.file.url or response.file.name
except AttributeError:
return False
else:
return True
return False
return (
super().is_download_response(response)
and bool(getattr(response.file, 'url', None) or getattr(response.file, 'name', None))
)
class DownloadDispatcher: