我正在尝试使Visual Studio代码格式化(带有颜色,而不是布局)带有类型注释(提示)的Python代码。对于以下代码,这样做失败:
from typing import Iterator
# return math.factorial(x)
def fib(n: int) -> Iterator[int]:
a, b = 0, 1
while a < n:
yield a
a, b = b, a + b
"""
This function checks whether a string is a palindrome.
s - The string to check.
"""
def is_palindrome(s: str) -> bool:
return s == s[::-1]
"""
This function compares two strings of word letters and returns the percentage match.
p_string1 - The first letters to compare.
p_string2 - The second letters to compare.
"""
def compare_letters(p_string1: str, p_string2: str) -> float:
return 1.0
我正在使用,"python.formatting.provider": "black"
但我也尝试过autopep8
和yapf
。通过在类型注释后将它们混合在一起,它们似乎都以相同的方式失败。
当我进入black
网站并将代码粘贴到Black Playground时,它仍然可以正常工作。
我已经升级使用python -m pip install --upgrade black
,它显示的版本与Black Playground(black-19.10b0)相同,所以不确定在哪里是Visual Studio Code问题或我问题。
我正在使用WinPython 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32
。
不太确定该如何通过这些lint,格式(颜色/布局),Python解析等来记录bug。
在Visual Studio Code中格式化Python类型注释是否成功,有人使用过什么设置?
更新:当我使用时,不会发生这种情况code --disable-extensions
。有谁知道我可以有选择地禁用扩展名以找出引起问题的扩展名吗?
卸载Python for VSCode
扩展程序解决了该问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句