简体   繁体   English

为什么 VSC 会抛出此代码的语法错误?

[英]Why does VSC throw syntax errors with this code?

I do not simply ask for advice on why something isn't working as intended, but as to why VSC or my linter (ProSpector) seems to think it is wrong.我不只是询问为什么某些事情没有按预期工作,而是询问为什么 VSC 或我的 linter (ProSpector) 似乎认为这是错误的。 I'm a little stuck and after reverting my code back to how it used to be, it seems to still show it as an error.我有点卡住了,在将我的代码恢复到以前的状态后,它似乎仍然显示为错误。

@cmd.add_command(name='addgroup', aliases=['ag',])
def add_group(group):
  if group in mods:
    print(f'{color["blue"]}{group}{color["red"]} is a duplicate. Try something different.{color["reset"]}')
  else:
    mods[group] = []

Something is wrong with this code, and it is not my objects, as they are all defined.这段代码有问题,它不是我的对象,因为它们都是定义的。 This is some kind of syntax error:这是某种语法错误: 错误截图

Any help is greatly appreciated because I'm so unsure of the issue.非常感谢任何帮助,因为我不确定这个问题。 In all honesty, it might be VSC messing up, because my code still runs fine, but I really am not sure.老实说,这可能是 VSC 搞砸了,因为我的代码仍然运行良好,但我真的不确定。

The weirdest part about this issue is that it seemingly has no cause.关于这个问题最奇怪的部分是它似乎没有原因。 I have found a fix for it while writing this question and will list it below:我在写这个问题时找到了解决方法,并将在下面列出:

  • Cut Code剪切代码
  • Paste Code粘贴代码

奇怪,但我没有抱怨

Done.完毕。 Why does this fix this weird persistent error that wouldn't go away when I retype code?为什么这会修复这个奇怪的持续错误,当我重新输入代码时,它不会消失? I have no clue, but the cut and paste method works, so there we go.我不知道,但剪切和粘贴方法有效,所以我们开始了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM