diff options
| author | Daniyal <abbasi.daniyal98@gmail.com> | 2021-03-16 21:11:27 +0530 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-19 08:04:37 +0100 |
| commit | 474cc420bf6bc1067e2aaa4b40cf6a08d62096f7 (patch) | |
| tree | 1281ae03beab376bbc08c0741da3b91d285cc2e3 /django | |
| parent | 37044817f9a57126d655f216019e8c8cca7c151b (diff) | |
Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.core.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/checks/messages.py | 3 | ||||
| -rw-r--r-- | django/core/checks/registry.py | 9 | ||||
| -rw-r--r-- | django/core/files/storage.py | 3 | ||||
| -rw-r--r-- | django/core/mail/message.py | 14 |
4 files changed, 19 insertions, 10 deletions
diff --git a/django/core/checks/messages.py b/django/core/checks/messages.py index aacac632eb..0987c2d118 100644 --- a/django/core/checks/messages.py +++ b/django/core/checks/messages.py @@ -9,7 +9,8 @@ CRITICAL = 50 class CheckMessage: def __init__(self, level, msg, hint=None, obj=None, id=None): - assert isinstance(level, int), "The first argument should be level." + if not isinstance(level, int): + raise TypeError('The first argument should be level.') self.level = level self.msg = msg self.hint = hint diff --git a/django/core/checks/registry.py b/django/core/checks/registry.py index d54538e367..d7bfa49548 100644 --- a/django/core/checks/registry.py +++ b/django/core/checks/registry.py @@ -75,9 +75,12 @@ class CheckRegistry: for check in checks: new_errors = check(app_configs=app_configs, databases=databases) - assert is_iterable(new_errors), ( - "The function %r did not return a list. All functions registered " - "with the checks registry must return a list." % check) + if not is_iterable(new_errors): + raise TypeError( + 'The function %r did not return a list. All functions ' + 'registered with the checks registry must return a list.' + % check, + ) errors.extend(new_errors) return errors diff --git a/django/core/files/storage.py b/django/core/files/storage.py index 16f9d4e27b..29b0e4c9ed 100644 --- a/django/core/files/storage.py +++ b/django/core/files/storage.py @@ -294,7 +294,8 @@ class FileSystemStorage(Storage): return str(name).replace('\\', '/') def delete(self, name): - assert name, "The name argument is not allowed to be empty." + if not name: + raise ValueError('The name must be given to delete().') name = self.path(name) # If the file or directory exists, delete it from the filesystem. try: diff --git a/django/core/mail/message.py b/django/core/mail/message.py index 963542cd62..ccc8a769ea 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -296,11 +296,15 @@ class EmailMessage: mimetype to DEFAULT_ATTACHMENT_MIME_TYPE and don't decode the content. """ if isinstance(filename, MIMEBase): - assert content is None - assert mimetype is None + if content is not None or mimetype is not None: + raise ValueError( + 'content and mimetype must not be given when a MIMEBase ' + 'instance is provided.' + ) self.attachments.append(filename) + elif content is None: + raise ValueError('content must be provided.') else: - assert content is not None mimetype = mimetype or mimetypes.guess_type(filename)[0] or DEFAULT_ATTACHMENT_MIME_TYPE basetype, subtype = mimetype.split('/', 1) @@ -428,8 +432,8 @@ class EmailMultiAlternatives(EmailMessage): def attach_alternative(self, content, mimetype): """Attach an alternative content representation.""" - assert content is not None - assert mimetype is not None + if content is None or mimetype is None: + raise ValueError('Both content and mimetype must be provided.') self.alternatives.append((content, mimetype)) def _create_message(self, msg): |
