File: mypy_plugins.rst

package info (click to toggle)
python-returns 0.26.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,652 kB
  • sloc: python: 11,000; makefile: 18
file content (136 lines) | stat: -rw-r--r-- 3,000 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
.. _mypy-plugins:

mypy plugin
===========

We provide a custom ``mypy`` plugin to fix existing issues,
provide new awesome features,
and improve type-safety of things developers commonly use.


Installation
------------

``returns`` has ``[compatible-mypy]`` extra to install the supported version.

.. code:: bash

  pip install 'returns[compatible-mypy]'

Or you can install ``mypy`` separately and check that version is supported.


Enabling our mypy plugin
------------------------

To install our ``mypy`` plugin add it
to the ``plugins`` section of the config file (``setup.cfg`` or ``mypy.ini``):

.. code:: ini

  [mypy]
  plugins =
    returns.contrib.mypy.returns_plugin

Or in ``pyproject.toml``:

.. code:: toml

  [tool.mypy]
  plugins = ["returns.contrib.mypy.returns_plugin"]

We recommend to always add our plugin as the first one in chain.


Configuration
-------------

You can have a look at the suggested ``mypy``
`configuration <https://github.com/dry-python/returns/blob/master/setup.cfg>`_
in our own repository.

You can also use `nitpick <https://wemake-python-styleguide.readthedocs.io/en/latest/pages/usage/integrations/nitpick.html>`_
tool to enforce the same ``mypy`` configuration for all your projects.

We recommend to use our own setup. Add this to your ``pyproject.toml``:

.. code:: toml

  [tool.nitpick]
  style = "https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/mypy.toml"

And use ``flake8`` to lint that configuration
defined in the setup matches yours.
This will allow to keep them in sync with the upstream.


Supported features
------------------

- ``kind`` feature adds Higher Kinded Types (HKT) support
- ``curry`` feature allows to write typed curried functions
- ``partial`` feature allows to write typed partial application
- ``flow`` feature allows to write better typed functional pipelines
  with ``flow`` function
- ``pipe`` feature allows to write better typed functional pipelines
  with ``pipe`` function
- ``do-notation`` feature allows using :ref:`do-notation`


Further reading
---------------

- `Mypy official docs <https://mypy.readthedocs.io/en/stable/index.html>`_
- `Mypy plugins docs <https://mypy.readthedocs.io/en/stable/extending_mypy.html>`_


API Reference
-------------

Plugin definition
~~~~~~~~~~~~~~~~~

.. automodule:: returns.contrib.mypy._consts
  :members:

.. autoclasstree:: returns.contrib.mypy.returns_plugin
  :strict:

.. automodule:: returns.contrib.mypy.returns_plugin
  :members:

Kind
~~~~

.. automodule:: returns.contrib.mypy._features.kind
  :members:

Curry
~~~~~

.. automodule:: returns.contrib.mypy._features.curry
  :members:

Partial
~~~~~~~

.. automodule:: returns.contrib.mypy._features.partial
  :members:

Flow
~~~~

.. automodule:: returns.contrib.mypy._features.flow
  :members:

Pipe
~~~~

.. automodule:: returns.contrib.mypy._features.pipe
  :members:

Do notation
~~~~~~~~~~~

.. automodule:: returns.contrib.mypy._features.do_notation
  :members: