跳到内容

lru-cache-without-parameters (UP011)

源自 pyupgrade linter。

修复总是可用的。

作用

检查 functools.lru_cache 装饰器上不必要的括号。

为什么这不好?

自 Python 3.8 起,functools.lru_cache 可以用作装饰器,无需尾随括号,只要没有参数传递给它。

示例

import functools


@functools.lru_cache()
def foo(): ...

建议改为

import functools


@functools.lru_cache
def foo(): ...

Options (选项)

参考