Skip to content

Commit 32aa73f

Browse files
authored
Replace custom mypy plugin for decorators with ParamSpec (#1196)
* Replace custom mypy plugin for decorators with `ParamSpec` * Some style * Fixes sphinx * Fixes CI
1 parent 57be41c commit 32aa73f

15 files changed

+569
-683
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ Versions before `1.0.0` are `0Ver`-based:
55
incremental in minor, bugfixes only are patches.
66
See [0Ver](https://0ver.org/).
77

8-
## 0.17.1
8+
9+
## 0.18.0 WIP
10+
11+
### Features
12+
13+
- Now requires `typing_extensions>=4.0`
14+
- Now requires `mypy>=0.930`
15+
- Removes plugin for `@safe`, `@maybe`, `@future`, etc.
16+
Because we now use `ParamSpec` type to properly type decorators
917

1018
### Bugfixes
1119

1220
- Fixes `__slots__` not being set properly in containers and their base classes
1321
- Fixes patching of containers in pytest plugin not undone after each test
1422

23+
1524
## 0.17.0
1625

1726
### Features

docs/conf.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,9 @@
1313
import os
1414
import sys
1515

16-
import sphinx
17-
1816
sys.path.insert(0, os.path.abspath('..'))
1917

2018

21-
# -- Monkeypatches -----------------------------------------------------------
22-
23-
def _monkeypatch(cls):
24-
"""Decorator to monkey-patch methods."""
25-
def decorator(func):
26-
method = func.__name__
27-
old = getattr(cls, method)
28-
setattr(
29-
cls,
30-
method,
31-
lambda inst, *args, **kwargs: func(inst, old, *args, **kwargs),
32-
)
33-
return decorator
34-
35-
36-
# workaround until https://github.com/miyakogi/m2r/pull/55 is merged
37-
@_monkeypatch(sphinx.registry.SphinxComponentRegistry)
38-
def add_source_parser(self, _old_add_source_parser, *args, **kwargs):
39-
"""This function changed in sphinx v3.0, we need to fix it back."""
40-
# signature is (parser: "Type[Parser]", override: bool = False),
41-
# but m2r expects the removed (str, parser: Type[Parser], **kwargs).
42-
if not isinstance(args[0], str):
43-
return _old_add_source_parser(self, *args, **kwargs)
44-
45-
4619
# -- Project information -----------------------------------------------------
4720

4821
def _get_project_meta():
@@ -80,7 +53,7 @@ def _get_project_meta():
8053
'sphinx.ext.napoleon',
8154

8255
# Used to include .md files:
83-
'm2r',
56+
'm2r2',
8457

8558
# Used to insert typehints into the final docs:
8659
'sphinx_autodoc_typehints',

docs/pages/contrib/mypy_plugins.rst

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ Supported features
5858
with ``flow`` function
5959
- ``pipe`` feature allows to write better typed functional pipelines
6060
with ``pipe`` function
61-
- ``decorators`` allows to infer types of functions that are decorated
62-
with ``@safe``, ``@maybe``, ``@impure``, etc
6361

6462

6563
Further reading
@@ -128,12 +126,3 @@ Pipe
128126

129127
.. automodule:: returns.contrib.mypy._features.pipe
130128
:members:
131-
132-
Decorators
133-
~~~~~~~~~~
134-
135-
.. autoclasstree:: returns.contrib.mypy._features.decorators
136-
:strict:
137-
138-
.. automodule:: returns.contrib.mypy._features.decorators
139-
:members:

docs/pages/types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You might face recursion problems with it:
4747
>>> Fold.loop(items, Reader.from_value(0), lambda x: lambda y: x + y)(...)
4848
Traceback (most recent call last):
4949
...
50-
RecursionError: maximum recursion depth exceeded in comparison
50+
RecursionError: ...
5151
5252
So, let's change how it works for this specific type:
5353

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sphinxcontrib-mermaid==0.7.1
77
sphinx-typlog-theme==0.8.0
88
sphinx-hoverxref==1.0.0
99
recommonmark==0.7.1
10-
m2r==0.2.1
10+
m2r2==0.3.2
1111
tomlkit==0.8.0
1212
pygments==2.10.0
1313

0 commit comments

Comments
 (0)