Merge pull request #607 from ProtixIT/cleanup-factory

Minor cleanup of the code handling `UrlsafeTokenField`'s `factory` argument
This commit is contained in:
Jelmer 2024-04-03 08:52:26 +02:00 committed by GitHub
commit 89653b2d24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,7 +1,6 @@
import secrets
import uuid
import warnings
from collections.abc import Callable
from django.conf import settings
from django.core.exceptions import ValidationError
@ -346,8 +345,8 @@ class UrlsafeTokenField(models.CharField):
non-callable value for factory is not supported.
"""
if factory is not None and not isinstance(factory, Callable):
raise TypeError("'factory' should either be a callable not 'None'")
if factory is not None and not callable(factory):
raise TypeError("'factory' should either be a callable or 'None'")
self._factory = factory
kwargs.pop('default', None) # passing default value has not effect.