VSCode IntelliSense认为存在一个Python的’function()’类。

huangapple go评论140阅读模式
英文:

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 时提供了自动完成:

VSCode IntelliSense认为存在一个Python的’function()’类。

function 在这个范围内未定义,但 IntelliSense 似乎认为它是定义的:

VSCode IntelliSense认为存在一个Python的’function()’类。

一些版本信息:

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 &quot;/home/hayesall/wip.py&quot;, line 4, in &lt;module&gt;
    foo(0)
  File &quot;/home/hayesall/wip.py&quot;, line 2, in foo
    return function(value)
NameError: name &#39;function&#39; 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:

VSCode IntelliSense认为存在一个Python的’function()’类。


function is not defined in this scope, but IntelliSense seems to think that it is:

VSCode IntelliSense认为存在一个Python的’function()’类。


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

&lt;class &#39;function&#39;&gt;

huangapple
  • 本文由 发表于 2023年2月18日 22:59:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定