From b8e54f51f548693e63ca27b02596a617e2a7f52e Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Thu, 2 Dec 2021 05:17:29 +0100 Subject: [PATCH] better compare(), especially now it's doing what's expected (and documented) --- tools.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tools.py b/tools.py index a11be26..c47e9cd 100644 --- a/tools.py +++ b/tools.py @@ -1,6 +1,7 @@ import inspect import os.path import sys +from typing import Any def get_script_dir(follow_symlinks=True): @@ -19,11 +20,6 @@ def get_script_dir(follow_symlinks=True): 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""" - if a > b: - return -1 - elif b > a: - return 1 - else: - return 0 + return bool(a > b) - bool(a < b)