# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/10_base.ipynb.

# %% auto 0
__all__ = ['GenericDuck', 'Duck', 'DuckModule']

# %% ../nbs/10_base.ipynb 6
import sys, copy

# %% ../nbs/10_base.ipynb 8
from types import ModuleType
from typing import Protocol, Generic

# %% ../nbs/10_base.ipynb 10
#| export

# %% ../nbs/10_base.ipynb 12
#| export

# %% ../nbs/10_base.ipynb 14
from .cons import DUCK_ATTRS
from .type import P, T, Ts
from .meta import DuckModuleMeta, ABCDuck, ABCParam

# %% ../nbs/10_base.ipynb 17
class GenericParam(Generic[*Ts, P], metaclass=ABCParam):
    ...

# %% ../nbs/10_base.ipynb 19
class GenericDuck(Generic[*Ts, P], metaclass=ABCDuck): 
    @classmethod
    def __metahook__(cls, mcls, name, bases, namespace, **kwargs):
        # print('base.__metahook__', cls, mcls, name, bases, namespace, **kwargs)
        return cls

# %% ../nbs/10_base.ipynb 22
class Duck(Protocol[*Ts, P], metaclass=ABCDuck):
    '''A class representing a duck-type.'''
    def __new__(cls, *args, **kwargs):
        # print('base.__new__', cls, args, kwargs)
        super().__new__(*args, **kwargs)
        
    def __init__(cls, *args, **kwargs):
        # print('base.__init__', cls, args, kwargs)
        super().__init__(*args, **kwargs)

    @classmethod
    def __metahook__(cls, mcls, name, bases, namespace, **kwargs):
        # print('base.__metahook__', cls, mcls, name, bases, namespace, **kwargs)
        return cls
        
    def __init_subclass__(cls, *args, **kwargs):
        # print('base.__init_subclass__', cls, args, kwargs)
        super().__init_subclass__(*args, **kwargs)
        for attr in DUCK_ATTRS:
            if (aval := getattr(cls, attr, None)) is not None:
                setattr(cls, attr, copy.copy(aval))

# %% ../nbs/10_base.ipynb 30
class DuckModule(ModuleType, metaclass=DuckModuleMeta):
    ...
