Skip to content

Commit 44b9341

Browse files
authored
Merge pull request #452 from numpy/docs/markdown-extensions
πŸ“ spice up the docs using markdown extensions
2 parents 4f16238 + 27c7b31 commit 44b9341

File tree

4 files changed

+114
-21
lines changed

4 files changed

+114
-21
lines changed

β€Ždocs/user_guide/differences.mdβ€Ž

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,92 @@ But the now concrete scalar types will no longer accept *any* `#!py floating[T]`
4444

4545
Type parameters can instead use an abstract scalar type as an upper bound. So instead of
4646

47+
/// tab | Python 3.10 and above
48+
4749
```py
48-
def f[T: npt.NBitBase](x: np.floating[T]) -> np.floating[T]: ...
50+
import numpy as np
51+
import numpy.typing as npt
52+
from typing import TypeVar
53+
54+
NT = TypeVar("NT", bound=npt.NBitBase)
55+
56+
def f(x: np.floating[NT]) -> np.floating[NT]: ...
57+
```
58+
59+
///
60+
/// tab | Python 3.12 and above
61+
select: True
62+
63+
```py
64+
import numpy as np
65+
import numpy.typing as npt
66+
67+
def f[NT: npt.NBitBase](x: np.floating[NT]) -> np.floating[NT]: ...
4968
```
5069

70+
///
71+
5172
you can write
5273

74+
/// tab | Python 3.10 and above
75+
5376
```py
77+
import numpy as np
78+
from typing import TypeVar
79+
80+
FloatT = TypeVar("FloatT", bound=np.floating)
81+
82+
def f(x: FloatT) -> FloatT: ...
83+
```
84+
85+
///
86+
/// tab | Python 3.12 and above
87+
select: True
88+
89+
```py
90+
import numpy as np
91+
5492
def f[FloatT: np.floating](x: FloatT) -> FloatT: ...
5593
```
5694

95+
///
96+
5797
As you can see, this also makes the code more readable.
5898

5999
But what if that isn't possible? For instance, you might have the following function:
60100

101+
/// tab | Python 3.10 and above
102+
61103
```py
62-
def f[T: npt.NBitBase](x: np.complexfloating[T]) -> np.floating[T]: ...
104+
import numpy as np
105+
import numpy.typing as npt
106+
from typing import TypeVar
107+
108+
NT = TypeVar("NT", bound=npt.NBitBase)
109+
110+
def f(x: np.complexfloating[NT]) -> np.floating[NT]: ...
63111
```
64112

113+
///
114+
/// tab | Python 3.12 and above
115+
select: True
116+
117+
```py
118+
import numpy as np
119+
import numpy.typing as npt
120+
121+
def f[NT: npt.NBitBase](x: np.complexfloating[NT]) -> np.floating[NT]: ...
122+
```
123+
124+
///
125+
65126
In that case, you can rewrite it by using
66127
[`#!py typing.overload`](https://typing.python.org/en/latest/spec/overload.html):
67128

68129
```py
130+
import numpy as np
131+
from typing import overload
132+
69133
@overload
70134
def f(x: np.complex64) -> np.float32: ...
71135
@overload

β€Žmkdocs.ymlβ€Ž

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,33 @@ plugins:
4444
show_source: false
4545
show_signature_annotations: true
4646

47-
# https://squidfunk.github.io/mkdocs-material/plugins/search/
48-
- search
49-
5047
# https://squidfunk.github.io/mkdocs-material/plugins/privacy/
5148
- privacy:
5249
enabled: !ENV [CI, false]
5350

51+
# https://squidfunk.github.io/mkdocs-material/plugins/search/
52+
- search
53+
5454
markdown_extensions:
5555
# https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown/
5656
- abbr
57-
- admonition
5857
- attr_list
5958
- def_list
6059
- footnotes
6160
- md_in_html
6261
- toc:
6362
permalink: "πŸ”—"
6463

64+
# https://github.com/oprypin/markdown-callouts
65+
- callouts
66+
67+
# https://facelessuser.github.io/pymdown-extensions/extensions/betterem/
68+
- pymdownx.betterem:
69+
smart_enable: asterisk
70+
71+
- pymdownx.blocks.tab:
72+
alternate_style: true
73+
6574
# https://facelessuser.github.io/pymdown-extensions/extensions/emoji/
6675
- pymdownx.emoji:
6776
emoji_index: !!python/name:material.extensions.emoji.twemoji
@@ -82,6 +91,24 @@ markdown_extensions:
8291
user: numpy
8392
repo: numtype
8493

94+
# https://facelessuser.github.io/pymdown-extensions/extensions/saneheaders/
95+
- pymdownx.saneheaders
96+
97+
extra:
98+
analytics:
99+
provider: google
100+
property: G-JYJJ7JYLG1
101+
consent:
102+
title: Cookie consent
103+
description: >-
104+
We use cookies to recognize your repeated visits and preferences, as well
105+
as to measure the effectiveness of our documentation and whether users
106+
find what they're searching for. With your consent, you're helping us to
107+
make our documentation better.
108+
109+
extra_css:
110+
- style/theme.css
111+
85112
theme:
86113
name: material
87114
favicon: img/favicon.ico
@@ -126,19 +153,4 @@ theme:
126153
icon: fontawesome/regular/sun
127154
name: Switch to system preference
128155

129-
extra_css:
130-
- style/theme.css
131-
132-
extra:
133-
analytics:
134-
provider: google
135-
property: G-JYJJ7JYLG1
136-
consent:
137-
title: Cookie consent
138-
description: >-
139-
We use cookies to recognize your repeated visits and preferences, as well
140-
as to measure the effectiveness of our documentation and whether users
141-
find what they're searching for. With your consent, you're helping us to
142-
make our documentation better.
143-
144156
copyright: Copyright ©, 2025 NumPy Developers.

β€Žpyproject.tomlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ typecheck = [
8181
docs = [
8282
"mkdocs-material>=9.6.10",
8383
"mkdocs-awesome-nav>=3.1.0",
84+
"markdown-callouts>=0.4.0",
8485
"mkdocs-include-markdown-plugin>=7.1.5",
8586
"mkdocs-minify-plugin>=0.8.0",
8687
"mkdocstrings[python]>=0.29.1",

β€Žuv.lockβ€Ž

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)