Skip to content

Commit 21b0a76

Browse files
authored
Adopt to IPython 8.22 (#1)
* Adopt to IPython 8.22 * Better typing
1 parent 4d7a8fc commit 21b0a76

File tree

7 files changed

+16
-83
lines changed

7 files changed

+16
-83
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Depends on [`docstring-to-markdown`](https://github.com/python-lsp/docstring-to-
1111

1212
## Installation
1313

14-
Requires `IPython` 8.21 or newer (which requires Python 3.10 or newer).
14+
Requires `IPython` 8.22 or newer (which requires Python 3.10 or newer).
1515

1616
```bash
1717
pip install ipython-markdown-inspector

ipython_markdown_inspector/__init__.py

+3-22
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
from functools import partial
2-
from typing import Any, List, Optional, Union
2+
from typing import List
33

44
from IPython.core.interactiveshell import InteractiveShell
5-
from IPython.core.oinspect import OInfo
5+
from IPython.core.oinspect import InspectorHookData
66

7-
from ._hook_data import InspectorHookData
87
from .formatter import as_markdown
98

109

1110
def hook(
12-
obj_or_data: Union[InspectorHookData, Any],
13-
info: Optional[OInfo] = None,
11+
data: InspectorHookData,
1412
*_,
1513
ipython: InteractiveShell,
1614
) -> str:
17-
if isinstance(obj_or_data, InspectorHookData):
18-
data = obj_or_data
19-
else:
20-
# fallback for IPython 8.21
21-
obj = obj_or_data
22-
detail_level = 0
23-
omit_sections: List[str] = []
24-
info_dict = ipython.inspector.info(
25-
obj, "", info=info, detail_level=detail_level
26-
)
27-
data = InspectorHookData(
28-
obj=obj,
29-
info=info,
30-
info_dict=info_dict,
31-
detail_level=detail_level,
32-
omit_sections=omit_sections,
33-
)
3415
return as_markdown(data)
3516

3617

ipython_markdown_inspector/_hook_data.py

-9
This file was deleted.

ipython_markdown_inspector/_ipython_patch.py

-40
This file was deleted.

ipython_markdown_inspector/formatter.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from typing import Dict, List
1+
from typing import cast, Dict, List
22

33
import docstring_to_markdown
4-
from IPython.core.oinspect import is_simple_callable
4+
from IPython.core.oinspect import is_simple_callable, InspectorHookData
55

6-
from ._hook_data import InspectorHookData
76
from .models import Field, CodeField, DocField, RowField
87

98

@@ -51,15 +50,15 @@
5150
"""
5251

5352

54-
def markdown_formatter(text: str):
53+
def markdown_formatter(text: str) -> str:
5554
try:
5655
converted = docstring_to_markdown.convert(text)
5756
return converted
5857
except docstring_to_markdown.UnknownFormatError:
5958
return f"<pre>{text}</pre>"
6059

6160

62-
def code_formatter(code, language="python"):
61+
def code_formatter(code: str, language="python") -> str:
6362
return f"```{language}\n{code}\n```"
6463

6564

@@ -97,8 +96,10 @@ def as_markdown(data: InspectorHookData) -> str:
9796
chunks.append(TABLE_STARTER)
9897
chunks[-1] += f"\n| {field.label} | `{value}` |"
9998
if field.kind == "code":
100-
chunks.append(f"#### {field.label}\n\n" + code_formatter(value))
99+
chunks.append(f"#### {field.label}\n\n" + code_formatter(cast(str, value)))
101100
if field.kind == "doc":
102-
chunks.append(f"#### {field.label}\n\n" + markdown_formatter(value))
101+
chunks.append(
102+
f"#### {field.label}\n\n" + markdown_formatter(cast(str, value))
103+
)
103104

104105
return "\n\n".join(chunks)

ipython_markdown_inspector/tests/test_as_markdown.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from IPython.core.interactiveshell import InteractiveShell
2+
from IPython.core.oinspect import InspectorHookData
23
from IPython import get_ipython
34
import pytest
45

56
from ipython_markdown_inspector.formatter import as_markdown
6-
from ipython_markdown_inspector._hook_data import InspectorHookData
77

88

99
def simple_func(arg):

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "ipython-markdown-inspector"
7-
version = "0.0.0"
7+
version = "1.0.0"
88
dependencies = [
9-
"ipython>=8.21.0",
10-
"docstring-to-markdown>=0.14.0,<1.0.0"
9+
"ipython>=8.22.0",
10+
"docstring-to-markdown>=0.15.0,<1.0.0"
1111
]
1212
requires-python = ">=3.10"
1313
authors = [

0 commit comments

Comments
 (0)