diff --git a/schema.py b/schema.py index 37b0fb1..1de61eb 100644 --- a/schema.py +++ b/schema.py @@ -2,7 +2,6 @@ obtained from config-files, forms, external services or command-line parsing, converted from JSON/YAML (or something else) to Python data-types.""" -import inspect import re try: @@ -274,10 +273,17 @@ def _priority(s): def _invoke_with_optional_kwargs(f, **kwargs): - s = inspect.signature(f) - if len(s.parameters) == 0: - return f() - return f(**kwargs) + try: + return f(**kwargs) + except TypeError as e: + if ( + e.args[0].startswith("{}() got an unexpected keyword argument".format(f.__name__)) # Python 2/3. + or e.args[0].startswith("{}() takes no arguments".format(f.__name__)) # Python 2 only. + ): + return f() + else: + raise + class Schema(object):