# Path: asynq/decorators.py
# def asynq(self, *args, **kwargs):
#     if self.instance is None:
#         return self.decorator.asynq(*args, **kwargs)
#     else:
#         return self.decorator.asynq(self.instance, *args, **kwargs)
# 
# Path: asynq/futures.py
# class ConstFuture(FutureBase):
#     """Future wrapping the constant."""
# 
#     def __init__(self, value):
#         self._value = _none
#         self._error = None
#         self.on_computed = (
#             core_events.sinking_event_hook
#         )  # Simple performance optimization
#         self.set_value(value)
#         self._in_repr = False  # since we don't call super.__init__
# 
#     def __reduce__(self):
#         return (ConstFuture, (self._value,))


import inspect
from unittest import mock
from .decorators import asynq
from .futures import ConstFuture

    def __call__(self, *args, **kwargs):
        return ConstFuture(self._mock_fn(*args, **kwargs))

    def __setattr__(self, attr, value):
        raise TypeError(
            "You cannot set attributes directly on a .asynq function. Set them on the "
            "function itself instead."
        )

    def __getattr__(self, attr):
        raise TypeError(
            "You cannot read attributes directly on a .asynq function. Read them on the"
            " function itself instead."
        )


def _maybe_wrap_new(new):
    """If the mock replacement cannot have attributes set on it, wraps it in a function.

    Also, if the replacement object is a method, applies the async() decorator.

    This is needed so that we support patch(..., x.method) where x.method is an instancemethod
    object, because instancemethods do not support attribute assignment.

    """
    if new is mock.DEFAULT:
        return new

    if inspect.isfunction(new) or isinstance(new, (classmethod, staticmethod)):

# Path: asynq/decorators.py
# def asynq(self, *args, **kwargs):
#     if self.instance is None:
#         return self.decorator.asynq(*args, **kwargs)
#     else:
#         return self.decorator.asynq(self.instance, *args, **kwargs)
# 
# Path: asynq/futures.py
# class ConstFuture(FutureBase):
#     """Future wrapping the constant."""
# 
#     def __init__(self, value):
#         self._value = _none
#         self._error = None
#         self.on_computed = (
#             core_events.sinking_event_hook
#         )  # Simple performance optimization
#         self.set_value(value)
#         self._in_repr = False  # since we don't call super.__init__
# 
#     def __reduce__(self):
#         return (ConstFuture, (self._value,))


# Path: asynq/mock_.py
import inspect
from unittest import mock
from .decorators import asynq
from .futures import ConstFuture


    def __call__(self, *args, **kwargs):
        return ConstFuture(self._mock_fn(*args, **kwargs))

    def __setattr__(self, attr, value):
        raise TypeError(
            "You cannot set attributes directly on a .asynq function. Set them on the "
            "function itself instead."
        )

    def __getattr__(self, attr):
        raise TypeError(
            "You cannot read attributes directly on a .asynq function. Read them on the"
            " function itself instead."
        )


def _maybe_wrap_new(new):
    """If the mock replacement cannot have attributes set on it, wraps it in a function.

    Also, if the replacement object is a method, applies the async() decorator.

    This is needed so that we support patch(..., x.method) where x.method is an instancemethod
    object, because instancemethods do not support attribute assignment.

    """
    if new is mock.DEFAULT:
        return new

    if inspect.isfunction(new) or isinstance(new, (classmethod, staticmethod)):

        return asynq(sync_fn=new)(new)