mypy_plugin.py¶
Last source¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | """Mypy plugin to declare our own functions to create ``attr`` classes and fields.
Inspired by https://github.com/python/mypy/issues/5406#issuecomment-490547091
"""
# type: ignore
# pylint: disable=no-name-in-module
from mypy.plugin import Plugin
from mypy.plugins.attrs import attr_attrib_makers, attr_class_makers
# pylint: enable=no-name-in-module
attr_class_makers.add("isshub.domain.utils.entity.validated")
attr_attrib_makers.add("isshub.domain.utils.entity.optional_field")
attr_attrib_makers.add("isshub.domain.utils.entity.required_field")
class MypyPlugin(Plugin):
"""Plugin class for mypy.
Notes
-----
Our plugin does nothing but it has to exist so this file gets loaded.
"""
def plugin(version: str): # pylint: disable=unused-argument
"""Define the plugin to use.
Parameters
----------
version : str
The version for which to return a plugin class. Ignored in our case.
Returns
-------
Type[Plugin]
The plugin class to be used by mypy
"""
return MypyPlugin
|
Changes¶
style(mypy): Remove most “type: ignore” pragmas¶
- Commit
- Hash
- Date
2020-10-04 20:36:50 +0200
- Type
Added
- Stats
+45 -0
@@ -0,0 +1,45 @@
+"""Mypy plugin to declare our own functions to create ``attr`` classes and fields.
+
+Inspired by https://github.com/python/mypy/issues/5406#issuecomment-490547091
+
+"""
+
+# type: ignore
+
+# pylint: disable=no-name-in-module
+from mypy.plugin import Plugin
+from mypy.plugins.attrs import attr_attrib_makers, attr_class_makers
+
+
+# pylint: enable=no-name-in-module
+
+
+attr_class_makers.add("isshub.domain.utils.entity.validated")
+attr_attrib_makers.add("isshub.domain.utils.entity.optional_field")
+attr_attrib_makers.add("isshub.domain.utils.entity.required_field")
+
+
+class MypyPlugin(Plugin):
+ """Plugin class for mypy.
+
+ Notes
+ -----
+ Our plugin does nothing but it has to exist so this file gets loaded.
+ """
+
+
+def plugin(version: str): # pylint: disable=unused-argument
+ """Define the plugin to use.
+
+ Parameters
+ ----------
+ version : str
+ The version for which to return a plugin class. Ignored in our case.
+
+ Returns
+ -------
+ Type[Plugin]
+ The plugin class to be used by mypy
+
+ """
+ return MypyPlugin