Skip to content

Replace custom mypy plugin for decorators with ParamSpec #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ Versions before `1.0.0` are `0Ver`-based:
incremental in minor, bugfixes only are patches.
See [0Ver](https://0ver.org/).

## 0.17.1

## 0.18.0 WIP

### Features

- Now requires `typing_extensions>=4.0`
- Now requires `mypy>=0.930`
- Removes plugin for `@safe`, `@maybe`, `@future`, etc.
Because we now use `ParamSpec` type to properly type decorators

### Bugfixes

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


## 0.17.0

### Features
Expand Down
29 changes: 1 addition & 28 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,9 @@
import os
import sys

import sphinx

sys.path.insert(0, os.path.abspath('..'))


# -- Monkeypatches -----------------------------------------------------------

def _monkeypatch(cls):
"""Decorator to monkey-patch methods."""
def decorator(func):
method = func.__name__
old = getattr(cls, method)
setattr(
cls,
method,
lambda inst, *args, **kwargs: func(inst, old, *args, **kwargs),
)
return decorator


# workaround until https://github.com/miyakogi/m2r/pull/55 is merged
@_monkeypatch(sphinx.registry.SphinxComponentRegistry)
def add_source_parser(self, _old_add_source_parser, *args, **kwargs):
"""This function changed in sphinx v3.0, we need to fix it back."""
# signature is (parser: "Type[Parser]", override: bool = False),
# but m2r expects the removed (str, parser: Type[Parser], **kwargs).
if not isinstance(args[0], str):
return _old_add_source_parser(self, *args, **kwargs)


# -- Project information -----------------------------------------------------

def _get_project_meta():
Expand Down Expand Up @@ -80,7 +53,7 @@ def _get_project_meta():
'sphinx.ext.napoleon',

# Used to include .md files:
'm2r',
'm2r2',

# Used to insert typehints into the final docs:
'sphinx_autodoc_typehints',
Expand Down
11 changes: 0 additions & 11 deletions docs/pages/contrib/mypy_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ Supported features
with ``flow`` function
- ``pipe`` feature allows to write better typed functional pipelines
with ``pipe`` function
- ``decorators`` allows to infer types of functions that are decorated
with ``@safe``, ``@maybe``, ``@impure``, etc


Further reading
Expand Down Expand Up @@ -128,12 +126,3 @@ Pipe

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

Decorators
~~~~~~~~~~

.. autoclasstree:: returns.contrib.mypy._features.decorators
:strict:

.. automodule:: returns.contrib.mypy._features.decorators
:members:
2 changes: 1 addition & 1 deletion docs/pages/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ You might face recursion problems with it:
>>> Fold.loop(items, Reader.from_value(0), lambda x: lambda y: x + y)(...)
Traceback (most recent call last):
...
RecursionError: maximum recursion depth exceeded in comparison
RecursionError: ...

So, let's change how it works for this specific type:

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sphinxcontrib-mermaid==0.7.1
sphinx-typlog-theme==0.8.0
sphinx-hoverxref==1.0.0
recommonmark==0.7.1
m2r==0.2.1
m2r2==0.3.2
tomlkit==0.8.0
pygments==2.10.0

Expand Down
Loading