Repository: django/django
File: django/utils/inspect.py (Python)

Code before:
    """
    return any(p for p in _get_callable_parameters(func) if p.kind == p.VAR_POSITIONAL)


def method_has_no_args(meth):
    """Return True if a method only accepts 'self'."""
    count = len([p for p in _get_callable_parameters(meth) if p.kind in ARG_KINDS])
    return count == 0 if inspect.ismethod(meth) else count == 1


def func_supports_parameter(func, name):
    return any(param.name == name for param in _get_callable_parameters(func))


def is_module_level_function(func):
    if not inspect.isfunction(func) or inspect.isbuiltin(func):
        return False

    if "<locals>" in func.__qualname__:
        return False

    return True


@contextmanager
def leave_deferred_annotations_unevaluated():
    """
    inspect.getfullargspec eagerly evaluates type annotations. To add
    compatibility with Python 3.14+ deferred evaluation, patch the module-level
    helper to provide the annotation_format that we are using elsewhere.

    This private helper could be removed when there is an upstream solution for
    https://github.com/python/cpython/issues/141560.
    """
    if not PY314:
        yield
        return
    with lock:
        helper_was_already_replaced = False
        if original_helper := getattr(inspect, "_signature_from_callable", None):
            helper_was_already_replaced = isinstance(original_helper, functools.partial)
            if not helper_was_already_replaced:
                inspect._signature_from_callable = safe_signature_from_callable
        try:
            yield
        finally:
            if original_helper and not helper_was_already_replaced:
                inspect._signature_from_callable = original_helper


Review comment (suggestion):
How about:

```suggestion
def lazy_deferred_annotations():
```


Code after:
    return any(p for p in _get_callable_parameters(func) if p.kind == p.VAR_POSITIONAL)


def method_has_no_args(meth):
    """Return True if a method only accepts 'self'."""
    count = len([p for p in _get_callable_parameters(meth) if p.kind in ARG_KINDS])
    return count == 0 if inspect.ismethod(meth) else count == 1


def func_supports_parameter(func, name):
    return any(param.name == name for param in _get_callable_parameters(func))


def is_module_level_function(func):
    if not inspect.isfunction(func) or inspect.isbuiltin(func):
        return False

    if "<locals>" in func.__qualname__:
        return False

    return True


@contextmanager
def lazy_annotations():
    """
    inspect.getfullargspec eagerly evaluates type annotations. To add
    compatibility with Python 3.14+ deferred evaluation, patch the module-level
    helper to provide the annotation_format that we are using elsewhere.

    This private helper could be removed when there is an upstream solution for
    https://github.com/python/cpython/issues/141560.

    This context manager is not reentrant.
    """
    if not PY314:
        yield
        return
    with lock:
        original_helper = inspect._signature_from_callable
        inspect._signature_from_callable = safe_signature_from_callable
        try:
            yield
        finally:
            inspect._signature_from_callable = original_helper