6
6
import os
7
7
from pathlib import Path , PurePath
8
8
from tempfile import TemporaryDirectory
9
- from typing import Literal
9
+ from typing import Literal , overload
10
10
11
11
try :
12
12
import IPython
@@ -353,6 +353,14 @@ def show(
353
353
)
354
354
raise GMTInvalidInput (msg )
355
355
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 : ...
356
364
def _preview (self , fmt : str , dpi : int , as_bytes : bool = False , ** kwargs ):
357
365
"""
358
366
Grab a preview of the figure.
@@ -380,7 +388,7 @@ def _preview(self, fmt: str, dpi: int, as_bytes: bool = False, **kwargs):
380
388
return fname .read_bytes ()
381
389
return fname
382
390
383
- def _repr_png_ (self ):
391
+ def _repr_png_ (self ) -> bytes :
384
392
"""
385
393
Show a PNG preview if the object is returned in an interactive shell.
386
394
@@ -389,7 +397,7 @@ def _repr_png_(self):
389
397
png = self ._preview (fmt = "png" , dpi = 70 , anti_alias = True , as_bytes = True )
390
398
return png
391
399
392
- def _repr_html_ (self ):
400
+ def _repr_html_ (self ) -> str :
393
401
"""
394
402
Show the PNG image embedded in HTML with a controlled width.
395
403
0 commit comments