Skip to content

Commit b80b44e

Browse files
authored
Figure: Add type hints to the _preview method (#3715)
1 parent b90fa46 commit b80b44e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pygmt/figure.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77
from pathlib import Path, PurePath
88
from tempfile import TemporaryDirectory
9-
from typing import Literal
9+
from typing import Literal, overload
1010

1111
try:
1212
import IPython
@@ -353,6 +353,14 @@ def show(
353353
)
354354
raise GMTInvalidInput(msg)
355355

356+
@overload
357+
def _preview(
358+
self, fmt: str, dpi: int, as_bytes: Literal[True] = True, **kwargs
359+
) -> bytes: ...
360+
@overload
361+
def _preview(
362+
self, fmt: str, dpi: int, as_bytes: Literal[False] = False, **kwargs
363+
) -> str: ...
356364
def _preview(self, fmt: str, dpi: int, as_bytes: bool = False, **kwargs):
357365
"""
358366
Grab a preview of the figure.
@@ -380,7 +388,7 @@ def _preview(self, fmt: str, dpi: int, as_bytes: bool = False, **kwargs):
380388
return fname.read_bytes()
381389
return fname
382390

383-
def _repr_png_(self):
391+
def _repr_png_(self) -> bytes:
384392
"""
385393
Show a PNG preview if the object is returned in an interactive shell.
386394
@@ -389,7 +397,7 @@ def _repr_png_(self):
389397
png = self._preview(fmt="png", dpi=70, anti_alias=True, as_bytes=True)
390398
return png
391399

392-
def _repr_html_(self):
400+
def _repr_html_(self) -> str:
393401
"""
394402
Show the PNG image embedded in HTML with a controlled width.
395403

0 commit comments

Comments
 (0)