【问题标题】:Intellisense not recognising type hinting for python 3Intellisense 无法识别 python 3 的类型提示
【发布时间】:2017-12-07 16:00:25
【问题描述】:

我想使用 Visual Studio 并使用类型提示(例如在函数参数列表中)查看智能感知,以测试变量的类型。

这可以通过isinstance(param,type) 语句来实现,但我想知道如果没有这些额外的语句,我们是否可以让它工作:

注意:我已经尝试使用 Visual Studio 和 Python Tools for Visual Studio 以及 2017 年初的 Visual Studio Preview,它内置了 python 支持,但似乎都不喜欢类型提示。

【问题讨论】:

  • 嗨 Robino,我在我的 VS 2017(15.2) 中使用 python 应用程序尝试了此代码,结果与您相同。研究python教程:docs.python.org/2/tutorial/classes.html和函数定义(def语句)没有像(xxx:str)这样的参数语法,我想你使用了错误的参数。您在第二个屏幕截图中预期的结果是由于语句“assert isinstance(bar,str)”,我测试了它,直接使用该语句定义另一个变量,它按您的预期工作,请查看此屏幕截图:@987654324 @
  • @Sara-MSFT 发布的代码没有错误。您在此处看到的语法称为“类型提示”,您可以在此处了解更多信息 docs.python.org/3/library/typing.html
  • 嗨 Robino,感谢您的更正,我已在此处向 Visual Studio 支持团队的 Python 工具报告了此问题:github.com/Microsoft/PTVS/issues/2773 并等待他们的确认,然后我将在此处更新.

标签: visual-studio python-3.x intellisense type-hinting ptvs


【解决方案1】:

确认后,此结果是设计的,请检查:Python 3.6: using type hints to describe a variable in the function argument list and the Quick Info of this variable display ‘unknown type’

Int19h:当前结果与预期一致,因为 PTVS 尚不支持类型提示来驱动代码完成。以下问题正在跟踪该功能:#82

【讨论】:

  • 感谢 LMMSCTFY(让我为您服务的 Microsoft 社区)的回答。这个问题的答案可能会随着时间而改变,所以如果发生这种情况(希望如此),我可能会取消选择“接受这个答案”。
  • 这是实现in this commit
猜你喜欢
  • 2021-06-30
  • 2023-03-17
  • 2013-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多