#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2020/6/4 14:41:10

@author: LiuKuan
@copyright: Apache License, Version 2.0
'''
from ._dump import *
from ._run import *
from pprint import pprint; pprint
import sys as _sys
import types as _types
#===============================================================================
#
#===============================================================================

try:
    main_module = _sys.modules['__main__']
except:
    pass

def print_eval(st):
    '''字符串打印并执行'''
    _frm = _sys._getframe(1)
    val = eval(st, _frm.f_globals, _frm.f_locals)
    print( f"{st} = {val}")

def print_type(t):
    '''打印类别'''
    _type_name = None
    for tname in dir(_types):
        if tname[0].isupper() and isinstance(t, getattr(_types, tname) ):
            _type_name = tname
            break
    if _type_name is None:
        _type_name = f"{type(t)}"
    print(_type_name)

def print_repr(v):
    '''打印 repr '''
    print(repr(v))

def line_num(depth = 1):
    '''获取当前行号'''
    return _sys._getframe(depth).f_lineno

def func_name(depth = 1):
    '''获取当前函数名字 '''
    return _sys._getframe(depth).f_code.co_name

def func_kws(depth = 1, skip_names = ("self", "cls")):
    ''' 获取函数的参数 '''
    _locals = _sys._getframe(depth).f_locals.copy()
    if skip_names:
        if isinstance(skip_names, str):
            _locals.pop(skip_names, None)
        else:
            for name in skip_names:
                _locals.pop(name, None)
    return _locals
