astroid无法推断structlog
创始人
2024-09-20 21:02:23
0

在代码中,我们可以使用 astroid 来检查代码并自动推断变量类型。但是,当我们在代码中使用 structlog.logger 来创建日志记录器时,astroid 无法自动推断其类型,产生了“astroid无法推断structlog”的错误。

为了解决这个问题,我们可以手动指定 structlog.logger 的类型。我们可以使用 astroidinference_tipregister 函数来完成这个任务。具体来说,我们可以在代码中添加以下代码:

import astroid

logger_inference_tip = """
def structlog_logger_tip(node):
    from structlog import ReturnLogger
    return [{'type': 'instance', 'value': ReturnLogger()}]
"""

astroid.inference_tip.register(
    astroid.parse(string=logger_inference_tip),
    astroid.inference.infer_call_result,
    astroid.matcher.matches_name('structlog.logger'),
)

这将向 astroid 提供一个手动推断 structlog.logger 类型的示例。现在,astroid 将能够正常地推断任何 structlog.logger 类型的变量。

相关内容

热门资讯

一直以来"hhpok... 一直以来"hhpoker德州有挂吗"werplan外开挂(切实是有辅助平台)-哔哩哔哩1、操作简单,...
据监测"大菠萝789... 据监测"大菠萝789辅助器下载"hhpoker有透视功能吗(切实是真的辅助平台)-哔哩哔哩1、大菠萝...
截至目前"wepok... 截至目前"wepoker软件安装包"wpk透视辅助下载(好像真的有辅助修改器)-哔哩哔哩wepoke...
备受关注的"hhpo... 备受关注的"hhpoker免费透视脚本"德扑圈透视(原来是有辅助插件)-哔哩哔哩1、hhpoker免...
透视插件"wepok... 透视插件"wepoker免费脚本咨询"wepoker代打辅助(真是是有辅助软件)-哔哩哔哩1、wep...
据文件显示"德普之星... 据文件显示"德普之星透视辅助软件"wepoker透视脚本免费使用视频(竟然是真的辅助插件)-哔哩哔哩...
在玩家背景下"wep... 在玩家背景下"wepoker科技辅助器"wepoker透视苹果系统(好像是有辅助工具)-哔哩哔哩we...
据通报"wepoke... 据通报"wepoker作必弊方法"wepoker手机插件(切实真的有辅助下载)-哔哩哔哩;1、金币登...
透视安卓版"we-p... 透视安卓版"we-poker靠谱吗"wepoker插件程序激活码(好像有辅助插件)-哔哩哔哩1、透视...
随着"wpk私人局有... 随着"wpk私人局有透视吗"wepoker破解工具(果然是有辅助修改器)-哔哩哔哩随着"wpk私人局...