Skip to content

Commit ebece3f

Browse files
authored
Handle misspecified args to dict (#39)
1 parent 1f6a921 commit ebece3f

15 files changed

+80
-43
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
2+
3+
name: Python tests
4+
5+
on:
6+
push:
7+
branches: [ master ]
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
python-version: ['3.7', '3.8', '3.9']
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- uses: actions/cache@v2
23+
with:
24+
path: |
25+
~/.cache/pip
26+
~/.cache/pre-commit
27+
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
28+
- name: dependencies
29+
run: |
30+
pip install --upgrade pip wheel
31+
pip install .[test,typehints]
32+
- name: tests
33+
run: pytest --color=yes

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v2.3.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- repo: https://github.com/psf/black
7+
rev: 20.8b1 # https://github.com/psf/black/tags
8+
hooks:
9+
- id: black
10+
language_version: python3
11+
- repo: https://github.com/pycqa/isort
12+
rev: 5.7.0
13+
hooks:
14+
- id: isort

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from sphinx.application import Sphinx
66

7+
78
# Allow importing scanpydoc itself
89
HERE = Path(__file__).parent
910
sys.path.insert(0, str(HERE.parent))
1011
import scanpydoc # noqa
1112

13+
1214
# Clean build env
1315
for file in HERE.glob("scanpydoc.*.rst"):
1416
file.unlink()

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,32 @@ requires = [
2424
]
2525

2626
[tool.flit.metadata.requires-extra]
27+
dev = [
28+
'pre-commit',
29+
]
2730
test = [
2831
'pytest',
2932
'pytest-cov',
30-
'pytest-black',
3133
'typing_extensions>=3.10; python_version<"3.8"',
3234
]
3335
doc = [
3436
'sphinx-autodoc-typehints>=1.12',
3537
'sphinx-rtd-theme',
3638
]
39+
typehints = ['sphinx-autodoc-typehints>=1.12']
40+
theme = ['sphinx-rtd-theme']
3741

3842
[tool.flit.entrypoints.'sphinx.html_themes']
3943
scanpydoc = 'scanpydoc.theme'
4044

4145
[tool.black]
4246
target-version = ['py37']
4347

48+
[tool.isort]
49+
profile = 'black'
50+
lines_after_imports = 2
51+
multi_line_output = 3
52+
4453
[tool.tox]
4554
legacy_tox_ini = """
4655
[tox]

scanpydoc/autosummary_generate_imported.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import logging
1414
from pathlib import Path
15-
from typing import Dict, Any
15+
from typing import Any, Dict
1616

1717
from sphinx.application import Sphinx
1818
from sphinx.ext import autosummary

scanpydoc/definition_list_typed_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
(e.g. function parameters) as definition lists instead of simple paragraphs.
66
"""
77

8-
from typing import Dict, List, Tuple, Any
8+
from typing import Any, Dict, List, Tuple
99

1010
from docutils import nodes
1111
from sphinx import addnodes
1212
from sphinx.application import Sphinx
13-
from sphinx.domains.python import PyTypedField, PyObject
13+
from sphinx.domains.python import PyObject, PyTypedField
1414
from sphinx.environment import BuildEnvironment
1515

1616
from . import _setup_sig, metadata

scanpydoc/elegant_typehints/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ def x() -> Tuple[int, float]:
4848
from pathlib import Path
4949
from typing import Any, Dict
5050

51-
5251
import sphinx_autodoc_typehints
52+
from docutils.parsers.rst import roles
5353
from sphinx.application import Sphinx
5454
from sphinx.config import Config
55-
from docutils.parsers.rst import roles
5655
from sphinx.ext.autodoc import ClassDocumenter
5756

5857
from .. import _setup_sig, metadata
@@ -96,7 +95,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
9695
app.add_css_file("typehints.css")
9796
app.connect("config-inited", _init_vars)
9897

99-
from .formatting import format_annotation, _role_annot
98+
from .formatting import _role_annot, format_annotation
10099

101100
sphinx_autodoc_typehints.format_annotation = format_annotation
102101
for name in ["annotation-terse", "annotation-full"]:

scanpydoc/elegant_typehints/autodoc_patch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from functools import wraps
2-
from typing import Mapping, Callable, Tuple
2+
from typing import Callable, Mapping, Tuple
33

44
from docutils.statemachine import StringList
55
from sphinx.ext.autodoc import ClassDocumenter

scanpydoc/elegant_typehints/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, Union, Optional
1+
from typing import Dict, Optional, Union
22

33

44
def example_func(a: Optional[str], b: Union[str, int, None] = None) -> Dict[str, int]:

scanpydoc/elegant_typehints/formatting.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
import inspect
21
import collections.abc as cabc
2+
import inspect
33
from functools import partial
4-
from typing import Any, Union # Meta
5-
from typing import Type, Sequence, Iterable # ABC
6-
from typing import Dict, List, Tuple # Concrete
4+
from typing import Any, Dict, Iterable, List, Sequence, Tuple, Type, Union
5+
76

87
try: # 3.8 additions
98
from typing import Literal, get_args, get_origin
109
except ImportError:
1110
from typing_extensions import Literal, get_args, get_origin
1211

1312
import sphinx_autodoc_typehints
14-
from sphinx_autodoc_typehints import format_annotation as _format_orig
1513
from docutils import nodes
1614
from docutils.nodes import Node
1715
from docutils.parsers.rst.roles import set_classes
1816
from docutils.parsers.rst.states import Inliner, Struct
1917
from docutils.utils import SystemMessage, unescape
18+
from sphinx_autodoc_typehints import format_annotation as _format_orig
2019

2120
from scanpydoc import elegant_typehints
2221

@@ -72,8 +71,8 @@ def _format_terse(
7271
return f":py:class:`{tilde}typing.Mapping`"
7372

7473
# display dict as {k: v}
75-
if origin is dict:
76-
k, v = get_args(annotation)
74+
if origin is dict and len(args) == 2:
75+
k, v = args
7776
return f"{{{fmt(k)}: {fmt(v)}}}"
7877

7978
# display Callable[[a1, a2], r] as (a1, a2) -> r

scanpydoc/elegant_typehints/return_tuple.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import inspect
22
import re
33
from logging import getLogger
4-
from typing import get_type_hints, Any, Union, Optional, Type, Tuple, List
4+
from typing import Any, List, Optional, Tuple, Type, Union, get_type_hints
5+
56

67
try: # 3.8 additions
78
from typing import get_args, get_origin

scanpydoc/rtd_github_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import sys
4040
from pathlib import Path, PurePosixPath
4141
from types import ModuleType
42-
from typing import Dict, Any, Tuple
42+
from typing import Any, Dict, Tuple
4343

4444
from jinja2.defaults import DEFAULT_FILTERS
4545
from sphinx.application import Sphinx

tests/test_elegant_typehints.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import typing as t
55
from pathlib import Path
66

7+
78
try: # 3.8 additions
89
from typing import Literal, get_args, get_origin
910
except ImportError:
@@ -14,9 +15,9 @@
1415
from sphinx.application import Sphinx
1516

1617
from scanpydoc.elegant_typehints.formatting import (
17-
format_annotation,
18-
_format_terse,
1918
_format_full,
19+
_format_terse,
20+
format_annotation,
2021
)
2122
from scanpydoc.elegant_typehints.return_tuple import process_docstring
2223

tests/test_rtd_github_links.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import pytest
44
from _pytest.monkeypatch import MonkeyPatch
55

6-
from scanpydoc.rtd_github_links import github_url, _get_linenos, _get_obj_module
6+
from scanpydoc.rtd_github_links import _get_linenos, _get_obj_module, github_url
7+
78

89
HERE = Path(__file__).parent
910

0 commit comments

Comments
 (0)