Skip to content

Commit 6bd742e

Browse files
committed
pygmt.set_display: Fix a bug when setting method=None, add type hints and refactor
1 parent 2409284 commit 6bd742e

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

pygmt/figure.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -568,22 +568,20 @@ def _repr_html_(self):
568568
)
569569

570570

571-
def set_display(method=None):
571+
def set_display(method: Literal["external", "notebook", "none", None] = None):
572572
"""
573573
Set the display method when calling :meth:`pygmt.Figure.show`.
574574
575575
Parameters
576576
----------
577-
method : str or None
577+
method
578578
The method to display an image preview. Choose from:
579579
580580
- ``"external"``: External PDF preview using the default PDF viewer
581581
- ``"notebook"``: Inline PNG preview in the current notebook
582582
- ``"none"``: Disable image preview
583-
- ``None``: Reset to the default display method
584-
585-
The default display method is ``"external"`` in Python consoles or
586-
``"notebook"`` in Jupyter notebooks.
583+
- ``None``: Reset to the default display method, which is either ``"external"``
584+
in Python consoles or ``"notebook"`` in Jupyter notebooks.
587585
588586
Examples
589587
--------
@@ -606,10 +604,13 @@ def set_display(method=None):
606604
>>> pygmt.set_display(method=None)
607605
>>> fig.show() # again, will show a PNG image in the current notebook
608606
"""
609-
if method in {"notebook", "external", "none"}:
610-
SHOW_CONFIG["method"] = method
611-
elif method is not None:
612-
raise GMTInvalidInput(
613-
f"Invalid display mode '{method}', "
614-
"should be either 'notebook', 'external', 'none' or None."
615-
)
607+
match method:
608+
case "external" | "notebook" | "none":
609+
SHOW_CONFIG["method"] = method
610+
case None:
611+
SHOW_CONFIG["method"] = _get_default_display_method()
612+
case _:
613+
raise GMTInvalidInput(
614+
f"Invalid display method '{method}'. Valid values are 'external',"
615+
"'notebook', 'none' or None."
616+
)

0 commit comments

Comments
 (0)