util.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:MonkeyType 作者: Instagram 项目源码 文件源码
def get_func_in_module(module: str, qualname: str) -> Callable:
    """Return the function specified by qualname in module.

    Raises:
        NameLookupError if we can't find the named function
        InvalidTypeError if we the name isn't a function
    """
    func = get_name_in_module(module, qualname)
    # TODO: Incorrect typeshed stub, stop arg should be optional
    # https://github.com/python/typeshed/blob/master/stdlib/3/inspect.pyi#L213
    func = inspect.unwrap(func)  # type: ignore
    if isinstance(func, types.MethodType):
        func = func.__func__
    elif isinstance(func, property):
        if func.fget is not None:
            if (func.fset is None) and (func.fdel is None):
                func = func.fget
            else:
                raise InvalidTypeError(
                    f"Property {module}.{qualname} has setter or deleter.")
        else:
            raise InvalidTypeError(
                f"Property {module}.{qualname} is missing getter")
    elif not isinstance(func, (types.FunctionType, types.BuiltinFunctionType)):
        raise InvalidTypeError(
            f"{module}.{qualname} is of type '{type(func)}', not function.")
    return func
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号