From 44394463e04b414b8ce64e794d12514ec8966f3d Mon Sep 17 00:00:00 2001 From: novafacing Date: Sun, 19 Sep 2021 22:07:46 -0400 Subject: [PATCH] Maintain backward compatibility with Python < 3.10 --- pwndbg/memoize.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pwndbg/memoize.py b/pwndbg/memoize.py index ca7736cbc..67abe17af 100644 --- a/pwndbg/memoize.py +++ b/pwndbg/memoize.py @@ -6,7 +6,6 @@ e.g. execution stops because of a SIGINT or breakpoint, or a new library/objfile are loaded, etc. """ -import collections import functools import sys @@ -14,6 +13,13 @@ import gdb import pwndbg.events +try: + # Python >= 3.10 + from collections.abc import Hashable +except ImportError: + # Python < 3.10 + from collections import Hashable + debug = False @@ -32,7 +38,7 @@ class memoize: def __call__(self, *args, **kwargs): how = None - if not isinstance(args, collections.abc.Hashable): + if not isinstance(args, Hashable): print("Cannot memoize %r!", file=sys.stderr) how = "Not memoizeable!" value = self.func(*args)