Skip to content

Commit

Permalink
Use callable() builtin function over isinstance(..., Callable)
Browse files Browse the repository at this point in the history
This is slightly more compact, but the main motivation is to work
around the following mypy bug:

python/mypy#3060
  • Loading branch information
mthuurne committed Mar 22, 2024
1 parent 35b4922 commit a60d2e0
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions model_utils/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import secrets
import uuid
import warnings
from collections.abc import Callable

from django.conf import settings
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -340,7 +339,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

Expand Down

0 comments on commit a60d2e0

Please sign in to comment.