为什么pylint告诉我我的dict属性是一个未定义的变量?

Sam*_*ole 1 python pylint python-3.x

我正在使用为python 3+配置的pylint处理此代码:

import utils

valid_commands = ['category', 'help', 'exit']

def createCategory():
    utils.clear()
    category = {
        name: 'test' <- allegedly undefined
    }
    utils.insertCategory(category)

def listActions():
    utils.clear()
    for command in valid_commands:
        print(command)

def exit():
    utils.clear()

actions = {
    'category': createCategory,
    'help':     listActions,
    'exit':     exit
}

command = ''
while command != 'exit':
    command = input('task_tracker> ')
    if command in valid_commands:
        actions[command]()
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

在此输入图像描述

我的代码运行正常,但这个错误不会消失的事实让我疯狂.为什么它告诉我这是未定义的?

gal*_*her 5

字典键应该是不可变值,或者是包含不可变值(如字符串或数字)的变量.name不是字符串,并且未在当前范围中定义为变量.解决这个问题的一种方法是

def createCategory():
    utils.clear()
    category = {
        'name': 'test'
    }
    utils.insertCategory(category)
Run Code Online (Sandbox Code Playgroud)