From 9879b748576cbbc705460f64d1098dd455bceb13 Mon Sep 17 00:00:00 2001 From: Chris Robertson Date: Mon, 20 Mar 2023 18:37:49 +0100 Subject: [PATCH] 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 --- model_utils/fields.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/model_utils/fields.py b/model_utils/fields.py index 216ec85..10e22fa 100644 --- a/model_utils/fields.py +++ b/model_utils/fields.py @@ -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 @@ def __init__(self, editable=False, max_length=128, factory=None, **kwargs): 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