Skip to content

Reference

Mixed methods.

MixedMethod

Bases: Generic[T, P, R, Q, S]

Represents mixed methods.

Source code in mixed_methods/core.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@final
@frozen()
class MixedMethod(Generic[T, P, R, Q, S]):
    """Represents mixed methods."""

    type_method: Callable[Concatenate[Type[T], P], R]
    """The type method to use."""
    instance_method: Callable[Concatenate[T, Q], S]
    """The instance method to use."""

    @overload
    def __get__(self, instance: None, type: Type[T]) -> Callable[P, R]:
        ...

    @overload
    def __get__(self, instance: T, type: Optional[Type[T]] = None) -> Callable[Q, S]:
        ...

    def __get__(
        self, instance: Optional[T], type: Optional[Type[T]] = None
    ) -> Union[Callable[P, R], Callable[Q, S]]:
        if instance is None:
            return self.type_method.__get__(instance, type)  # type: ignore

        return self.instance_method.__get__(instance, type)  # type: ignore

type_method: Callable[Concatenate[Type[T], P], R] instance-attribute

The type method to use.

instance_method: Callable[Concatenate[T, Q], S] instance-attribute

The instance method to use.

mixed_method(type_method: Callable[Concatenate[Type[T], P], R], instance_method: Callable[Concatenate[T, Q], S]) -> MixedMethod[T, P, R, Q, S]

Creates mixed methods.

Parameters:

Name Type Description Default
type_method Callable[Concatenate[Type[T], P], R]

The type method of the mixed method.

required
instance_method Callable[Concatenate[T, Q], S]

The instance method of the mixed method.

required

Returns:

Type Description
MixedMethod[T, P, R, Q, S]

The created mixed method.

Source code in mixed_methods/core.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def mixed_method(
    type_method: Callable[Concatenate[Type[T], P], R],
    instance_method: Callable[Concatenate[T, Q], S],
) -> MixedMethod[T, P, R, Q, S]:
    """Creates mixed methods.

    Arguments:
        type_method: The type method of the mixed method.
        instance_method: The instance method of the mixed method.

    Returns:
        The created mixed method.
    """
    return MixedMethod(type_method, instance_method)