Remove busy-work. (#2072)
It is entirely sufficient to walk the MRO of the exception class, no need to check for classes re-appearing later on, no need to add the MRO of any superclass. * Python refuses point-blank to create a class with a circular MRO. * All classes in a superclass MRO *already* appear in the MRO of the derived type. Re-adding the contents of a superclass MRO is doing double work.
This commit is contained in:
parent
6478d7bb99
commit
de1652467b
1 changed files with 1 additions and 13 deletions
14
flask/app.py
14
flask/app.py
|
|
@ -14,7 +14,6 @@ from threading import Lock
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper
|
||||||
from collections import deque
|
|
||||||
|
|
||||||
from werkzeug.datastructures import ImmutableDict
|
from werkzeug.datastructures import ImmutableDict
|
||||||
from werkzeug.routing import Map, Rule, RequestRedirect, BuildError
|
from werkzeug.routing import Map, Rule, RequestRedirect, BuildError
|
||||||
|
|
@ -1437,24 +1436,13 @@ class Flask(_PackageBoundObject):
|
||||||
def find_handler(handler_map):
|
def find_handler(handler_map):
|
||||||
if not handler_map:
|
if not handler_map:
|
||||||
return
|
return
|
||||||
queue = deque(exc_class.__mro__)
|
for cls in exc_class.__mro__:
|
||||||
# Protect from geniuses who might create circular references in
|
|
||||||
# __mro__
|
|
||||||
done = set()
|
|
||||||
|
|
||||||
while queue:
|
|
||||||
cls = queue.popleft()
|
|
||||||
if cls in done:
|
|
||||||
continue
|
|
||||||
done.add(cls)
|
|
||||||
handler = handler_map.get(cls)
|
handler = handler_map.get(cls)
|
||||||
if handler is not None:
|
if handler is not None:
|
||||||
# cache for next time exc_class is raised
|
# cache for next time exc_class is raised
|
||||||
handler_map[exc_class] = handler
|
handler_map[exc_class] = handler
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
queue.extend(cls.__mro__)
|
|
||||||
|
|
||||||
# try blueprint handlers
|
# try blueprint handlers
|
||||||
handler = find_handler(self.error_handler_spec
|
handler = find_handler(self.error_handler_spec
|
||||||
.get(request.blueprint, {})
|
.get(request.blueprint, {})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue