英文:
VSCode IntelliSense thinks a Python 'function()' class exists
问题
在这个情况下,VSCode / IntelliSense正在自动完成一个名为 function()
的Python类,但似乎该类并不存在。
例如,以下代码看起来是有效的:
def foo(value):
return function(value)
foo(0)
但是,在这个范围内未定义 function
,因此运行时会引发 NameError
:
Traceback (most recent call last):
File "/home/hayesall/wip.py", line 4, in <module>
foo(0)
File "/home/hayesall/wip.py", line 2, in foo
return function(value)
NameError: name 'function' is not defined
我期望 IntelliSense 能够警告我 function
未定义。function()
似乎没有文档字符串,我在更广泛的Python/CPython/VSCode文档中也找不到有关它的任何信息。 (附注: pylint
识别为 "Undefined variable 'function'")。
function()
是什么?或者:有关为什么 IntelliSense 匹配它的解释吗?
屏幕截图:
输入单词 function
时提供了自动完成:
function
在这个范围内未定义,但 IntelliSense 似乎认为它是定义的:
一些版本信息:
Debian
code 1.75.1 (x86)
Pylance v2023.2.30
Python 3.9.15 (CPython, GCC 11.2.0)
英文:
VSCode / IntelliSense is completing a Python class called function()
that does not appear to exist.
For example, this appears to be valid code:
def foo(value):
return function(value)
foo(0)
But function
is not defined in this scope, so running this raises a NameError
:
Traceback (most recent call last):
File "/home/hayesall/wip.py", line 4, in <module>
foo(0)
File "/home/hayesall/wip.py", line 2, in foo
return function(value)
NameError: name 'function' is not defined
I expected IntelliSense to warn me about function
being undefined. function()
does not appear to have a docstring, and I cannot find anything about it in the wider Python/CPython/VSCode documentation. (Side note: pylint
recognizes "Undefined variable 'function'").
What is function()
? Or: is there an explanation for why IntelliSense is matching this?
Screenshots:
Writing the word function
provides an autocomplete:
function
is not defined in this scope, but IntelliSense seems to think that it is:
Some version info:
Debian
code 1.75.1 (x86)
Pylance v2023.2.30
Python 3.9.15 (CPython, GCC 11.2.0)
答案1
得分: 1
function
类型是函数的一种类型(在 Python 中,函数是对象),考虑到
def return_one():
return 1
print(type(return_one))
输出为
<class 'function'>
英文:
function
class is type of function (functions are objects in python
), consider that
def return_one():
return 1
print(type(return_one))
gives output
<class 'function'>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论