1010import re
1111import subprocess
1212import sys
13+ import typing as t
1314from distutils .version import LooseVersion
1415
1516from . import exc
@@ -374,10 +375,16 @@ def get_by_id(self, id):
374375
375376
376377def which (
377- exe = None ,
378- default_paths = ["/bin" , "/sbin" , "/usr/bin" , "/usr/sbin" , "/usr/local/bin" ],
379- append_env_path = True ,
380- ):
378+ exe : str ,
379+ default_paths : t .List [str ] = [
380+ "/bin" ,
381+ "/sbin" ,
382+ "/usr/bin" ,
383+ "/usr/sbin" ,
384+ "/usr/local/bin" ,
385+ ],
386+ append_env_path : bool = True ,
387+ ) -> t .Optional [str ]:
381388 """
382389 Return path of bin. Python clone of /usr/bin/which.
383390
@@ -401,7 +408,7 @@ def which(
401408 from salt.util - https://www.github.com/saltstack/salt - license apache
402409 """
403410
404- def _is_executable_file_or_link (exe ) :
411+ def _is_executable_file_or_link (exe : str ) -> bool :
405412 # check for os.X_OK doesn't suffice because directory may executable
406413 return os .access (exe , os .X_OK ) and (os .path .isfile (exe ) or os .path .islink (exe ))
407414
@@ -434,7 +441,7 @@ def _is_executable_file_or_link(exe):
434441 return None
435442
436443
437- def get_version ():
444+ def get_version () -> LooseVersion :
438445 """
439446 Return tmux version.
440447
@@ -471,7 +478,7 @@ def get_version():
471478 return LooseVersion (version )
472479
473480
474- def has_version (version ) :
481+ def has_version (version : str ) -> bool :
475482 """
476483 Return affirmative if tmux version installed.
477484
@@ -488,7 +495,7 @@ def has_version(version):
488495 return get_version () == LooseVersion (version )
489496
490497
491- def has_gt_version (min_version ) :
498+ def has_gt_version (min_version : str ) -> bool :
492499 """
493500 Return affirmative if tmux version greater than minimum.
494501
@@ -505,7 +512,7 @@ def has_gt_version(min_version):
505512 return get_version () > LooseVersion (min_version )
506513
507514
508- def has_gte_version (min_version ) :
515+ def has_gte_version (min_version : str ) -> bool :
509516 """
510517 Return True if tmux version greater or equal to minimum.
511518
@@ -522,7 +529,7 @@ def has_gte_version(min_version):
522529 return get_version () >= LooseVersion (min_version )
523530
524531
525- def has_lte_version (max_version ) :
532+ def has_lte_version (max_version : str ) -> bool :
526533 """
527534 Return True if tmux version less or equal to minimum.
528535
@@ -539,7 +546,7 @@ def has_lte_version(max_version):
539546 return get_version () <= LooseVersion (max_version )
540547
541548
542- def has_lt_version (max_version ) :
549+ def has_lt_version (max_version : str ) -> bool :
543550 """
544551 Return True if tmux version less than minimum.
545552
@@ -556,7 +563,7 @@ def has_lt_version(max_version):
556563 return get_version () < LooseVersion (max_version )
557564
558565
559- def has_minimum_version (raises = True ):
566+ def has_minimum_version (raises : bool = True ) -> bool :
560567 """
561568 Return if tmux meets version requirement. Version >1.8 or above.
562569
@@ -598,7 +605,7 @@ def has_minimum_version(raises=True):
598605 return True
599606
600607
601- def session_check_name (session_name ):
608+ def session_check_name (session_name : str ):
602609 """
603610 Raises exception session name invalid, modeled after tmux function.
604611
@@ -627,7 +634,7 @@ def session_check_name(session_name):
627634 )
628635
629636
630- def handle_option_error (error ):
637+ def handle_option_error (error : str ):
631638 """Raises exception if error in option command found.
632639
633640 In tmux 3.0, show-option and show-window-otion return invalid option instead of
@@ -664,7 +671,7 @@ def handle_option_error(error):
664671 raise exc .OptionError (error ) # Raise generic option error
665672
666673
667- def get_libtmux_version ():
674+ def get_libtmux_version () -> LooseVersion :
668675 """Return libtmux version is a PEP386 compliant format.
669676
670677 Returns
0 commit comments