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#14928
  • Loading branch information
mthuurne committed Mar 20, 2023
1 parent 7fd664f commit b2337a6
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 @@ -2,7 +2,6 @@

import secrets
import uuid
from collections.abc import Callable

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

Please sign in to comment.