From 178de848a873a57fd42774b23f581d01d9b1ea16 Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Tue, 27 Sep 2022 17:30:27 +0200 Subject: [PATCH 1/8] add typehint in plot_contour to test extension --- src/ansys/dpf/post/result_data.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 4d6443765..1c453d537 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -322,7 +322,7 @@ def _sort_fields_container_with_labels(self, option_id, display_option): new_fields_container.add_field(label, field) return new_fields_container - def plot_contour(self, display_option: str = "time", option_id=1, **kwargs): + def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwargs): """Plot the contour result on its mesh support. The obtained figure depends on the support, which can be a @@ -333,9 +333,9 @@ def plot_contour(self, display_option: str = "time", option_id=1, **kwargs): Parameters ---------- - display_option : str, optional + display_option : optional Name of the label to display. The default is ``"time"``. - option_id: int, optional + option_id: optional Label ID to display. The default is ``1``. **kwargs : optional Additional keyword arguments for the plotter. For keyword From e8ce70866daaf65cfff55fb4645b61e7a82c9d57 Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Tue, 27 Sep 2022 17:48:37 +0200 Subject: [PATCH 2/8] add autodoc_typehints variable --- docs/source/conf.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index e86ff551a..7f926a246 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,6 +55,8 @@ "sphinx_gallery.gen_gallery", ] +autodoc_typehints = "description" + # Intersphinx mapping intersphinx_mapping = { "python": ("https://docs.python.org/dev", None), From 9c838a22592e7263a1518261d07e36bb1867cb16 Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Tue, 27 Sep 2022 18:09:53 +0200 Subject: [PATCH 3/8] follow exact notation in sphinx-autodoc-typehints documentation --- src/ansys/dpf/post/result_data.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 1c453d537..0b5918c0e 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -333,11 +333,9 @@ def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwarg Parameters ---------- - display_option : optional - Name of the label to display. The default is ``"time"``. - option_id: optional - Label ID to display. The default is ``1``. - **kwargs : optional + :display_option: Name of the label to display. The default is ``"time"``. + :option_id: Label ID to display. The default is ``1``. + :**kwargs: optional Additional keyword arguments for the plotter. For keyword arguments, see ``help(pyvista.plot)``. From 7384392f1c512f5a00e5d45797e1fdc6e9b65ea6 Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Tue, 27 Sep 2022 19:29:42 +0200 Subject: [PATCH 4/8] working version when docs generated locally --- .gitignore | 4 +++- requirements/requirements_docs.txt | 2 +- src/ansys/dpf/post/result_data.py | 10 ++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4f2bf16ba..7a2ef162c 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,9 @@ instance/ .scrapy # Sphinx documentation -doc/build/ +docs/_build/ +docs/source/api/_autosummary +docs/source/examples # PyBuilder .pybuilder/ diff --git a/requirements/requirements_docs.txt b/requirements/requirements_docs.txt index f1057de4e..d24e6185e 100644 --- a/requirements/requirements_docs.txt +++ b/requirements/requirements_docs.txt @@ -11,4 +11,4 @@ sphinx-notfound-page==0.8.3 sphinx-copybutton==0.5.0 sphinx-gallery==0.11.1 ansys_sphinx_theme==0.5.2 -sphinx-autodoc-typehints +sphinx-autodoc-typehints==1.19.1 diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 0b5918c0e..33cfdd8d8 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -333,11 +333,13 @@ def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwarg Parameters ---------- - :display_option: Name of the label to display. The default is ``"time"``. - :option_id: Label ID to display. The default is ``1``. - :**kwargs: optional + display_option : + Name of the label to display. Optional, the default is ``"time"``. + option_id : + Label ID to display. Optional, the default is ``1``. + **kwargs : Additional keyword arguments for the plotter. For keyword - arguments, see ``help(pyvista.plot)``. + arguments, see ``help(pyvista.plot)``. Optional. Examples -------- From c416d865f4e412b8459950f56f52bd20bbc0cbfc Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Fri, 30 Sep 2022 15:53:18 +0200 Subject: [PATCH 5/8] typehints example in plot_contour --- .gitignore | 2 +- docs/source/conf.py | 3 ++- src/ansys/dpf/post/result_data.py | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7a2ef162c..ae4721326 100644 --- a/.gitignore +++ b/.gitignore @@ -71,7 +71,7 @@ instance/ .scrapy # Sphinx documentation -docs/_build/ +docs/build/ docs/source/api/_autosummary docs/source/examples diff --git a/docs/source/conf.py b/docs/source/conf.py index 7f926a246..53da65342 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,7 +55,8 @@ "sphinx_gallery.gen_gallery", ] -autodoc_typehints = "description" +typehints_defaults = "comma" +simplify_optional_unions = False # Intersphinx mapping intersphinx_mapping = { diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 33cfdd8d8..8a42fec65 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -3,6 +3,7 @@ This module, which is used heavily in DPF-Post, is a fields container wrapper. """ from textwrap import wrap +from typing import Optional from ansys.dpf.core import FieldsContainer, Operator from ansys.dpf.core import errors as core_errors @@ -322,7 +323,7 @@ def _sort_fields_container_with_labels(self, option_id, display_option): new_fields_container.add_field(label, field) return new_fields_container - def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwargs): + def plot_contour(self, display_option: Optional[str] = "time", option_id: Optional[int] = 1, **kwargs): """Plot the contour result on its mesh support. The obtained figure depends on the support, which can be a @@ -334,12 +335,12 @@ def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwarg Parameters ---------- display_option : - Name of the label to display. Optional, the default is ``"time"``. + Name of the label to display. option_id : - Label ID to display. Optional, the default is ``1``. + Label ID to display. **kwargs : Additional keyword arguments for the plotter. For keyword - arguments, see ``help(pyvista.plot)``. Optional. + arguments, see ``help(pyvista.plot)``. Examples -------- From 02bb1c88569ce504933996ed745fd542d1c9fccc Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Fri, 30 Sep 2022 16:02:05 +0200 Subject: [PATCH 6/8] fix style --- src/ansys/dpf/post/result_data.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 8a42fec65..36ca7b218 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -323,7 +323,12 @@ def _sort_fields_container_with_labels(self, option_id, display_option): new_fields_container.add_field(label, field) return new_fields_container - def plot_contour(self, display_option: Optional[str] = "time", option_id: Optional[int] = 1, **kwargs): + def plot_contour( + self, + display_option: Optional[str] = "time", + option_id: Optional[int] = 1, + **kwargs + ): """Plot the contour result on its mesh support. The obtained figure depends on the support, which can be a From 01e4536e974195fb09d2cd4a6510346d1020ec3f Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Fri, 30 Sep 2022 17:46:57 +0200 Subject: [PATCH 7/8] remove Optional --- src/ansys/dpf/post/result_data.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 36ca7b218..3d3d8f860 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -323,12 +323,7 @@ def _sort_fields_container_with_labels(self, option_id, display_option): new_fields_container.add_field(label, field) return new_fields_container - def plot_contour( - self, - display_option: Optional[str] = "time", - option_id: Optional[int] = 1, - **kwargs - ): + def plot_contour(self, display_option: str = "time", option_id: int = 1, **kwargs): """Plot the contour result on its mesh support. The obtained figure depends on the support, which can be a From 06283393896bafb1b124f28d9600df8946431cbe Mon Sep 17 00:00:00 2001 From: "guillem.barroso" Date: Fri, 30 Sep 2022 17:50:30 +0200 Subject: [PATCH 8/8] remove Optional --- src/ansys/dpf/post/result_data.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ansys/dpf/post/result_data.py b/src/ansys/dpf/post/result_data.py index 3d3d8f860..45f112cdb 100755 --- a/src/ansys/dpf/post/result_data.py +++ b/src/ansys/dpf/post/result_data.py @@ -3,7 +3,6 @@ This module, which is used heavily in DPF-Post, is a fields container wrapper. """ from textwrap import wrap -from typing import Optional from ansys.dpf.core import FieldsContainer, Operator from ansys.dpf.core import errors as core_errors