首页 > 解决方案 > 在 mypy 中为 jsonschema_typed 设置插件

问题描述

我想jsonschema_typed用 mypy 检查类型。我jsonschema_typed从 pip 安装: pip install jsonschema-typed

我有所有依赖项(jsonschema,mypy)。

并尝试了示例:

from jsonschema_typed.types import JSONSchema

data: JSONSchema['path/to/schema.json'] = dict(title='baz')
data['description'] = 'there is no description'  # TypedDict "FooSchema" has no key 'description'
data['awesome'] = 42
data['awesome'] = None  # Argument 2 has incompatible type "None"; expected "Union[int, float]"

但什么也没发生。我试图将插件写入 setup.cfg 文件:

plugins = jsonschema_typed.plugin.JSONSchemaPlugin.get_type_analyze_hook

但 mypy 显示该错误:

setup.cfg:10:1: error: Error importing plugin 'jsonschema_typed.plugin.JSONSchemaPlugin.get_type_analyze_hook'

你能帮助我吗?

标签: python-3.xmypy

解决方案


推荐阅读