mypy:具有动态生成的类变量的类,总是具有相同类型
我想拥有一个只存储字符串变量的数据类,类似的东西:
class Properties:
pass
class MyClass:
def __init__(self):
self.properties = Properties()
properties_json = self.get_properties_json()
for key, value in properties_json:
setattr(self.properties, key, value)
def get_properties_json(self) -> dict[str, str]:
...
我怎么能告诉mypy
,属性具有始终strings
的动态变量?
I'd like to have a data class that only stores string variables, something like this:
class Properties:
pass
class MyClass:
def __init__(self):
self.properties = Properties()
properties_json = self.get_properties_json()
for key, value in properties_json:
setattr(self.properties, key, value)
def get_properties_json(self) -> dict[str, str]:
...
How can I tell MyPy
that Properties has dynamic variables that are always strings
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论