Use boolean logic instead of any/all

Using and/or over any/all has a couple of advantages:

- it's a bit quicker
- it won't evaluate the second half at all if the first half fails – if
  it is in business hours, and convert_to_boolean would raise, with your
  use of all we'd throw a 500, whereas if we had or, business_hours
  would trip and we'd skip over the second half without worrying about
  exceptions

any and all are designed for use with variable length args eg
`any(x for x in thing())`
This commit is contained in:
Chris Hill-Scott
2017-02-02 09:15:48 +00:00
parent 199dc24cb8
commit 17a4d8ef3b
2 changed files with 8 additions and 8 deletions

View File

@@ -50,15 +50,15 @@ def feedback(ticket_type):
severe = request.args.get('severe')
urgent = any((
in_business_hours(),
urgent = (
in_business_hours() or
(ticket_type == 'problem' and convert_to_boolean(severe))
))
)
anonymous = all((
(not form.email_address.data),
(not current_user.is_authenticated),
))
anonymous = (
(not form.email_address.data) and
(not current_user.is_authenticated)
)
if needs_triage(ticket_type, severe):
session['feedback_message'] = form.feedback.data