From b4675818e8b842e4c11a1a1e4f8433c592eb5098 Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Mon, 18 Sep 2023 10:47:55 +0200 Subject: [PATCH] Remove version checks, and use AttributeError exception to skip if needed --- picard/audit.py | 6 +++++- picard/tagger.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/picard/audit.py b/picard/audit.py index 682eee28244..cf009268d40 100644 --- a/picard/audit.py +++ b/picard/audit.py @@ -49,7 +49,11 @@ def audit(event, args): secs = time.time() - start_time print(f'audit:{matched}:{tid}:{secs} {event} args={args}') - sys.addaudithook(audit) + try: + sys.addaudithook(audit) + except AttributeError: + # sys.addaudithook() appeared in Python 3.8 + pass def list_from_prefixes_string(prefixes_string): diff --git a/picard/tagger.py b/picard/tagger.py index 7bb9a79023d..f4c643c1993 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -257,9 +257,8 @@ def __init__(self, picard_args, localedir, autoupdate, pipe_handler=None): if picard_args.debug or "PICARD_DEBUG" in os.environ: self.set_log_level(logging.DEBUG) - if sys.version_info[:3] > (3, 8): - if picard_args.audit: - setup_audit(picard_args.audit) + if picard_args.audit: + setup_audit(picard_args.audit) # Main thread pool used for most background tasks self.thread_pool = QtCore.QThreadPool(self) @@ -1442,11 +1441,10 @@ def process_picard_args(): parser.add_argument("-display", nargs=1, help=argparse.SUPPRESS) # Picard specific arguments - if sys.version_info[:3] > (3, 8): - parser.add_argument("-a", "--audit", action='store', - default=None, - help="audit events passed as a comma-separated list, prefixes supported, " - "use all to match any (see https://docs.python.org/3/library/audit_events.html#audit-events)") + parser.add_argument("-a", "--audit", action='store', + default=None, + help="audit events passed as a comma-separated list, prefixes supported, " + "use all to match any (see https://docs.python.org/3/library/audit_events.html#audit-events)") parser.add_argument("-c", "--config-file", action='store', default=None, help="location of the configuration file")