我在编辑代码时需要使用Python的类function,但是将跟类function的代码加入后却出现如下错误:
Traceback (most recent call last):
File "x x x.py", line 58, in <module>
............................
^^^^^^^^
NameError: name 'function' is not defined
使用VSCode也可以在builtins.pyi找到该类:
class function:
# Make sure this class definition stays roughly in line with `types.FunctionType`
@property
def __closure__(self) -> tuple[_Cell, ...] | None: ...
__code__: CodeType
__defaults__: tuple[Any, ...] | None
__dict__: dict[str, Any]
@property
def __globals__(self) -> dict[str, Any]: ...
__name__: str
__qualname__: str
__annotations__: dict[str, Any]
__kwdefaults__: dict[str, Any]
if sys.version_info >= (3, 10):
@property
def __builtins__(self) -> dict[str, Any]: ...
__module__: str
# mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any.
def __get__(self, obj: object | None, type: type | None = ...) -> Any: ...
即使加入“from builtins import function”,却仍然抛出相同错误。
请问如何才能引用这个叫“function”的类?