diff options
author | Akihiro Motoki <amotoki@gmail.com> | 2021-02-18 11:57:02 +0900 |
---|---|---|
committer | Akihiro Motoki <amotoki@gmail.com> | 2021-02-18 12:01:44 +0900 |
commit | 0d447372c7a04f1cab800fa4b5a388c6d0b7d49e (patch) | |
tree | 1738dc37ca1e1d802ec154f2c5276db09b0f50af | |
parent | 6bf001ee6ac70ffb1bbcf670c4450e233bec6b7c (diff) | |
download | pyscss-0d447372c7a04f1cab800fa4b5a388c6d0b7d49e.tar.gz |
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().
-rw-r--r-- | scss/namespace.py | 13 |
1 files 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: |