From 0d447372c7a04f1cab800fa4b5a388c6d0b7d49e Mon Sep 17 00:00:00 2001 From: Akihiro Motoki Date: Thu, 18 Feb 2021 11:57:02 +0900 Subject: Fix DeprecationWarning on inspect.getargspec in python3 inspect.getargspec() is deprecated in python3 and the usage of inspect.signature() or inspect.getfullargspec() is recommended. The only different between getargspec and getfullargspec is that "keywords" attribute in getargspec() return value corresponds to "varkw" attribute in case of getfullargspec(). This commit changes the code to try getfullargspec() first and then fallback to getargspec(). --- scss/namespace.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scss/namespace.py b/scss/namespace.py index 939cde5..dab3aea 100644 --- a/scss/namespace.py +++ b/scss/namespace.py @@ -169,9 +169,16 @@ class Namespace(object): def _auto_register_function(self, function, name, ignore_args=0): name = name.replace('_', '-').rstrip('-') - argspec = inspect.getargspec(function) - - if argspec.varargs or argspec.keywords: + try: + argspec = inspect.getfullargspec(function) + varkw = argspec.varkw + except AttributeError: + # In python 2.7, getfulargspec does not exist. + # Let's use getargspec as fallback. + argspec = inspect.getargspec(function) + varkw = argspec.keywords + + if argspec.varargs or varkw: # Accepts some arbitrary number of arguments arities = [None] else: -- cgit v1.2.1