【问题标题】:Why does pycharm give "expected type" warning for None outside a class or function?为什么 pycharm 在类或函数之外对 None 给出“预期类型”警告?
【发布时间】:2019-10-05 02:15:06
【问题描述】:

为什么pycharm会在此代码中的类或函数之外对None给出“预期类型”警告:

def blah():
    hiya = None  # type: dict   # No type warning

class Foo:
    bar = None  # type: dict    # No type warning

asf = None  # type: dict        # Expected type 'dict', got 'None' instead

【问题讨论】:

  • 请用通用 [python] 标签标记所有 python 问题

标签: python python-3.x pycharm


【解决方案1】:

我正在使用 Pycharm,这对我来说很好用

def blah():
hiya = None  # type: #dict   # No type warning

class Foo:
    bar = None  # type: #dict    # No type warning

asf = None  # type: #dict        # Expected type 'dict', got 'None' instead

也许是你的设置。

【讨论】:

  • 您是说您没有asf 行上收到“预期类型”警告?你用的是什么版本的pycharm和python?我在 pycharm pro 2019.1 和 python 3.7.1
  • pycharm 的版本 = 2019.1.2 和 python 无关紧要 3.7
猜你喜欢
  • 2021-06-11
  • 2018-06-16
  • 2020-05-22
  • 1970-01-01
  • 2019-02-23
  • 2011-09-28
  • 1970-01-01
  • 2021-09-05
  • 2019-05-27
相关资源
最近更新 更多