Skip to content

Commit 3652b92

Browse files
committed
fix: typing hints
1 parent 0afd5b7 commit 3652b92

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

doc/source/conf.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from github import Github
1010
import pyvista
1111
import requests
12-
import sphinx
12+
from sphinx.addnodes import document as doctree
13+
from sphinx.application import Sphinx as App
1314
from sphinx.builders.latex import LaTeXBuilder
1415

1516
from ansys_sphinx_theme import (
@@ -27,7 +28,7 @@
2728
EXAMPLE_PATH = (THIS_PATH / "examples" / "sphinx_examples").resolve()
2829

2930
# To allow using 'helper' python file as a module
30-
sys.path.append(Path(__file__).parent)
31+
sys.path.append(str(Path(__file__).parent))
3132

3233
# Project information
3334
project = "ansys_sphinx_theme"
@@ -273,11 +274,11 @@ def download_and_process_files(example_links: List[str]) -> List[str]:
273274

274275

275276
def remove_edit_this_page_if_directive(
276-
app: sphinx.app,
277+
app: App,
277278
pagename: str,
278279
templatename: str,
279-
context: sphinx.context,
280-
doctree: sphinx.doctree,
280+
context: dict,
281+
doctree: doctree,
281282
page_vars: dict,
282283
):
283284
"""Remove 'edit this page' button.
@@ -287,15 +288,15 @@ def remove_edit_this_page_if_directive(
287288
288289
Parameters
289290
----------
290-
app : sphinx.app
291+
app : sphinx.application.Sphinx
291292
Sphinx app
292293
pagename : str
293294
Page name
294295
templatename : str
295296
Template name
296-
context : sphinx.context
297+
context : dict
297298
Page context
298-
doctree : sphinx.doctree
299+
doctree : sphinx.addnodes.document
299300
Page doctree
300301
page_vars : dict
301302
Page variables
@@ -308,11 +309,11 @@ def remove_edit_this_page_if_directive(
308309

309310

310311
def remove_show_source_if_directive(
311-
app: sphinx.app,
312+
app: App,
312313
pagename: str,
313314
templatename: str,
314-
context: sphinx.context,
315-
doctree: sphinx.doctree,
315+
context: dict,
316+
doctree: doctree,
316317
page_vars: dict,
317318
):
318319
"""Remove the 'show_source' link.
@@ -322,15 +323,15 @@ def remove_show_source_if_directive(
322323
323324
Parameters
324325
----------
325-
app : sphinx.app
326+
app : sphinx.application.Sphinx
326327
Sphinx app
327328
pagename : str
328329
Page name
329330
templatename : str
330331
Template name
331-
context : sphinx.context
332+
context : dict
332333
Page context
333-
doctree : sphinx.doctree
334+
doctree : sphinx.addnodes.document
334335
Page doctree
335336
page_vars : dict
336337
Page variables
@@ -342,27 +343,27 @@ def remove_show_source_if_directive(
342343

343344

344345
def pre_build_page_html(
345-
app: sphinx.app,
346+
app: App,
346347
pagename: str,
347348
templatename: str,
348-
context: sphinx.context,
349-
doctree: sphinx.doctree,
349+
context: dict,
350+
doctree: doctree,
350351
):
351352
"""Apply hooks before building HTML.
352353
353354
Apply the hooks as functions before building the HTML files.
354355
355356
Parameters
356357
----------
357-
app : sphinx.app
358+
app : sphinx.application.Sphinx
358359
Sphinx app
359360
pagename : str
360361
Page name
361362
templatename : str
362363
Template name
363-
context : sphinx.context
364+
context : dict
364365
Page context
365-
doctree : sphinx.doctree
366+
doctree : sphinx.addnodes.document
366367
Page doctree
367368
"""
368369
from helpers import get_page_vars
@@ -375,12 +376,12 @@ def pre_build_page_html(
375376
remove_show_source_if_directive(app, pagename, templatename, context, doctree, page_vars)
376377

377378

378-
def setup(app: sphinx):
379+
def setup(app: App):
379380
"""Add custom configuration to sphinx app.
380381
381382
Parameters
382383
----------
383-
app : sphinx.application.sphinx
384+
app : sphinx.application.Sphinxlication.sphinx
384385
The Sphinx application.
385386
"""
386387
from helpers import SetPageVariableDirective, add_custom_variables_to_context

doc/source/helpers.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"""Helper classes and functions for documentation build."""
22

33
from docutils.parsers.rst import Directive
4-
import sphinx
4+
from sphinx.addnodes import document as doctree
5+
from sphinx.application import Sphinx as App
56

67

7-
def get_page_vars(app: sphinx.app, pagename: str) -> dict:
8+
def get_page_vars(app: App, pagename: str) -> dict:
89
"""Get page variables.
910
1011
Get each page variables.
@@ -28,7 +29,7 @@ def get_page_vars(app: sphinx.app, pagename: str) -> dict:
2829
or not env.pages_vars
2930
or not env.pages_vars.get(pagename, None)
3031
):
31-
return
32+
return {}
3233

3334
return env.pages_vars[pagename]
3435

@@ -77,27 +78,27 @@ def run(self):
7778

7879

7980
def add_custom_variables_to_context(
80-
app: sphinx.app,
81+
app: App,
8182
pagename: str,
8283
templatename: str,
83-
context: sphinx.context,
84-
doctree: sphinx.doctree,
84+
context: dict,
85+
doctree: doctree,
8586
) -> None:
8687
"""Add customs variables to build context.
8788
8889
This is needed to be able to access the vars at the build stage.
8990
9091
Parameters
9192
----------
92-
app : Sphinx.app
93+
app : sphinx.application.Sphinx
9394
Sphinx app.
9495
pagename : str
9596
Page name
9697
templatename : str
9798
Template page
98-
context : Sphinx.context
99+
context : dict
99100
Page context
100-
doctree : Sphinx.doctree
101+
doctree : sphinx.addnodes.document
101102
Page doctree
102103
"""
103104
env = app.builder.env

0 commit comments

Comments
 (0)