我使用gettext包在Python应用程序中执行翻译。有一个自定义翻译类,它充当字符串的包装器,还定义了一个自定义内置函数
class Wrapper:
def __init__(self, message: str):
self.message = message
@classmethod
def install(cls):
import builtins
builtins._ = cls
test = _('translate me')在此代码上运行mypy时,我将收到错误
test.py: error: Name "_" is not defined有没有办法告诉mypy abou定制的内置函数?在flake8中,我能够用
[flake8]
builtins = _发布于 2022-02-13 00:29:31
如果我理解得很好,你需要的是:
_: Type[Wrapper]
test = _('translate me')https://stackoverflow.com/questions/71096892
复制相似问题