Use callable() builtin function over isinstance(..., Callable)

This is slightly more compact, but the main motivation is to work
around the following mypy bug:

https://github.com/python/mypy/issues/3060
This commit is contained in:
Maarten ter Huurne 2023-03-20 18:37:49 +01:00
parent e34de65480
commit 6c5ed66ef2

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,7 +345,7 @@ class UrlsafeTokenField(models.CharField):
non-callable value for factory is not supported.
"""
if factory is not None and not isinstance(factory, Callable):
if factory is not None and not callable(factory):
raise TypeError("'factory' should either be a callable or 'None'")
self._factory = factory