Skip to content

Commit 6fe66af

Browse files
SAT 1.22 compat (#63)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 909d481 commit 6fe66af

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ repos:
44
hooks:
55
- id: trailing-whitespace
66
- repo: https://github.com/psf/black
7-
rev: 22.12.0
7+
rev: 23.1.0
88
hooks:
99
- id: black
1010
language_version: python3
1111
- repo: https://github.com/pycqa/isort
12-
rev: 5.11.4
12+
rev: 5.12.0
1313
hooks:
1414
- id: isort

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"python.formatting.provider": "black",
4+
"python.testing.pytestArgs": ["-v"],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

scanpydoc/elegant_typehints/formatting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _format_terse(annotation: Type[Any], config: Config) -> str:
7878

7979

8080
def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]:
81-
r"""Generate reStructuredText containing links to the types.
81+
"""Generate reStructuredText containing links to the types.
8282
8383
Unlike :func:`sphinx_autodoc_typehints.format_annotation`,
8484
it tries to achieve a simpler style as seen in numeric packages like numpy.
@@ -93,7 +93,7 @@ def format_annotation(annotation: Type[Any], config: Config) -> Optional[str]:
9393

9494
curframe = inspect.currentframe()
9595
calframe = inspect.getouterframes(curframe, 2)
96-
if calframe[2].function == "process_docstring" or (
96+
if calframe[2].function in {"process_docstring", "_inject_signature"} or (
9797
calframe[2].function == "_inject_types_to_docstring"
9898
and calframe[3].function == "process_docstring"
9999
):

tests/test_elegant_typehints.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ def test_classes_get_added(app, parse):
193193
# t.NoReturn,
194194
t.Callable[[int], None],
195195
# t.ClassVar[t.Any],
196-
t.Optional[int],
197196
t.Tuple[int, str],
198197
t.Tuple[float, ...],
199198
t.Union[int, str],
@@ -212,9 +211,6 @@ def test_typing_classes(app, annotation, formatter):
212211
)
213212
if formatter is _format_terse and name in {"Union", "Callable"}:
214213
pytest.skip("Tested elsewhere")
215-
args = get_args(annotation)
216-
if name == "Union" and len(args) == 2 and type(None) in args:
217-
name = "Optional"
218214
output = formatter(annotation, app.config)
219215
assert output is None or output.startswith(f":py:data:`typing.{name}")
220216

@@ -331,9 +327,9 @@ def fn_test():
331327
if not re.match("^:(rtype|param|annotation-(full|terse)):", l)
332328
]
333329
assert lines == [
334-
rf":return: foo : {foo_rendered}",
330+
f":return: foo : {foo_rendered}",
335331
" A foo!",
336-
r" bar : :py:class:`int`",
332+
" bar : :py:class:`int`",
337333
" A bar!",
338334
]
339335

0 commit comments

Comments
 (0)