Fang-Pen Lin
2017-05-22 08422ee6340cbcd225dcfc26c7c0aa3165449a58
Fix #1603, add closest predicate name in error message
1 files modified
17 ■■■■ changed files
pyramid/config/util.py 17 ●●●● patch | view | raw | blame | history
pyramid/config/util.py
@@ -1,3 +1,4 @@
from difflib import get_close_matches
from hashlib import md5
import inspect
@@ -36,7 +37,7 @@
       config.add_view(
           'mypackage.views.my_view',
           route_name='ok',
           route_name='ok',
           request_method=not_('POST')
           )
@@ -69,7 +70,7 @@
        # if the underlying predicate doesnt return a value, it's not really
        # a predicate, it's just something pretending to be a predicate,
        # so dont update the hash
        if val:
        if val:
            val = '!' + val
        return val
@@ -90,7 +91,7 @@
# over = before
class PredicateList(object):
    def __init__(self):
        self.sorter = TopologicalSorter()
        self.last_added = None
@@ -152,7 +153,15 @@
                weights.append(1 << n + 1)
                preds.append(pred)
        if kw:
            raise ConfigurationError('Unknown predicate values: %r' % (kw,))
            closest = []
            names = [ name for name, _ in ordered ]
            for name in kw:
                closest.extend(get_close_matches(name, names, 3))
            raise ConfigurationError(
                'Unknown predicate values: %r (did you mean %s)'
                % (kw, ','.join(closest))
            )
        # A "order" is computed for the predicate list.  An order is
        # a scoring.
        #