【问题标题】:Pylint e1101: Class 'reddit' has no 'subreddit' memberPylint e1101:“reddit”类没有“subreddit”成员
【发布时间】:2019-05-30 16:25:39
【问题描述】:

我正在尝试从“memes”Reddit subreddit 上的前 10 个帖子中获取随机图像,但它给出了 E1101 pylint 错误。我似乎做的一切都是正确的。这是我的代码:

我似乎在这方面找不到任何东西。

reddit = praw.Reddit(client_id='my client ID',
    client_secret='my client secret',
    user_agent='my user agent',
    username='username')




@commands.command()
async def meme(self):
    memes = reddit.subreddit('memes').hot()
    post_to_pick = random.randint(1, 10)
    for i in range(0, post_to_pick):
        submission = next(x for x in memes if not x.stickied)

【问题讨论】:

  • 你能指出哪一行是 linter 抛出那个味精吗?
  • 如果一个类在运行时使用setattr 创建属性,Pylint 无法检测到这些。看到这个问题stackoverflow.com/q/35990313/494134
  • @ThuYeinTun memes = reddit.subreddit('memes').hot() reddit 特别
  • Here's the line where Reddit.subreddit is defined。我希望你的 linter 能看到这一点。您的prawpylint 安装都是最新版本吗?
  • praw 和 pylint 都更新了

标签: python bots discord discord.py praw


【解决方案1】:

这是因为 pylint 默认为 only trusts C extensions from the standard library 并且会忽略那些不是的。

由于 praw 不是 stdlib 的一部分,您必须手动将其列入白名单。为此,请在终端中导航到项目目录,并为 pylint 生成一个 rcfile:

$ pylint --generate-rcfile > .pylintrc

然后,打开该文件并将 praw 添加到白名单中,如下所示:

extension-pkg-whitelist=praw

在那之后,所有关于 praw 的 E1101 错误都不应该再出现了

More details in this answer.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 2016-06-29
    • 1970-01-01
    • 2019-01-11
    • 1970-01-01
    • 2019-03-24
    • 1970-01-01
    相关资源
    最近更新 更多