# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/05_fref.ipynb.

# %% auto 0
__all__ = ['isforwardref', 'isfref', 'dereference']

# %% ../nbs/05_fref.ipynb 4
from typing import TypeGuard
from typing import ForwardRef

# %% ../nbs/05_fref.ipynb 5
from .core import isstr, isnone

# %% ../nbs/05_fref.ipynb 7
def isforwardref(x) -> TypeGuard[ForwardRef]:
    '''Check if `x` is a `ForwardRef`
    
    See Also
    --------
    isfref : Alias for `isforwardref`.
    '''
    return isinstance(x, ForwardRef)

def isfref(x) -> TypeGuard[ForwardRef]:
    '''Check if `x` is a `ForwardRef`
    
    See Also
    --------
    isforwardref : Alias for `isfref`.
    '''
    return isforwardref(x)

# %% ../nbs/05_fref.ipynb 8
def dereference(
    ref: ForwardRef | str,
    is_argument: bool = False,
    module: str = None,
    *,
    is_class: bool = False,
    globalsns: dict = None, 
    localsns: dict = None, 
    recursive_guard: set = None
) -> type:
    '''Dereference a `ForwardRef` object.'''
    if not isforwardref(ref) and isstr(ref):
        ref = ForwardRef(ref, is_argument=is_argument, module=module, is_class=is_class)

    recursive_guard = set()     if isnone(recursive_guard) else recursive_guard
    localsns        = locals()  if isnone(localsns)        else localsns
    globalsns       = globals() if isnone(globalsns)       else globalsns
    val = ref._evaluate(globalsns, localsns, recursive_guard)
    return val
