better compare(), especially now it's doing what's expected (and documented)

This commit is contained in:
Stefan Harmuth 2021-12-02 05:17:29 +01:00
parent 5e3d5d1156
commit b8e54f51f5

View File

@ -1,6 +1,7 @@
import inspect import inspect
import os.path import os.path
import sys import sys
from typing import Any
def get_script_dir(follow_symlinks=True): def get_script_dir(follow_symlinks=True):
@ -19,11 +20,6 @@ def get_script_dir(follow_symlinks=True):
return os.path.dirname(path) return os.path.dirname(path)
def compare(a: int, b: int) -> int: def compare(a: Any, b: Any) -> int:
"""compare to values, return -1 if a is smaller than b, 1 if a is greater than b, 0 is both are equal""" """compare to values, return -1 if a is smaller than b, 1 if a is greater than b, 0 is both are equal"""
if a > b: return bool(a > b) - bool(a < b)
return -1
elif b > a:
return 1
else:
return 0