flake8 - misc flake8 errs.

* unused variables
* variables in loops overshadowing imports
* excepts with no defined exc type (tried to avoid `except Exception` too)
* history mapper is still too complex
* default variables should never be mutable
This commit is contained in:
Leo Hemsted
2017-11-28 13:49:14 +00:00
parent 28d5f9b87f
commit 28088428f1
6 changed files with 14 additions and 11 deletions

View File

@@ -35,7 +35,7 @@ def dao_update_annual_billing_for_current_and_future_years(service_id, free_sms_
if not financial_year_start:
financial_year_start = get_current_financial_year_start_year()
updated = AnnualBilling.query.filter(
AnnualBilling.query.filter(
AnnualBilling.service_id == service_id,
AnnualBilling.financial_year_start >= financial_year_start
).update(

View File

@@ -318,22 +318,22 @@ def dao_fetch_monthly_historical_stats_for_service(service_id, year):
)
months = {
datetime.strftime(date, '%Y-%m'): {
datetime.strftime(created_date, '%Y-%m'): {
template_type: dict.fromkeys(
NOTIFICATION_STATUS_TYPES,
0
)
for template_type in TEMPLATE_TYPES
}
for date in [
for created_date in [
datetime(year, month, 1) for month in range(4, 13)
] + [
datetime(year + 1, month, 1) for month in range(1, 4)
]
}
for notification_type, status, date, count in rows:
months[datetime.strftime(date, "%Y-%m")][notification_type][status] = count
for notification_type, status, created_date, count in rows:
months[datetime.strftime(created_date, "%Y-%m")][notification_type][status] = count
return months

View File

@@ -7,6 +7,7 @@ from notifications_utils.recipients import (
validate_and_format_email_address
)
from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTemplate, SMSMessageTemplate
from requests.exceptions import HTTPError
from app import clients, statsd_client, create_uuid
from app.dao.notifications_dao import (
@@ -60,7 +61,7 @@ def send_sms_to_provider(notification):
update_notification(notification, provider)
try:
send_sms_response(provider.get_name(), str(notification.id), notification.to)
except:
except HTTPError:
# when we retry, we only do anything if the notification is in created - it's currently in sending,
# so set it back so that we actually attempt the callback again
notification.sent_at = None

View File

@@ -33,7 +33,7 @@ def _is_versioning_col(col):
return "version_meta" in col.info
def _history_mapper(local_mapper):
def _history_mapper(local_mapper): # noqa (C901 too complex)
cls = local_mapper.class_
# set the "active_history" flag

View File

@@ -33,9 +33,9 @@ from app.utils import get_template_instance
def _validate_positive_number(value, msg="Not a positive integer"):
try:
page_int = int(value)
if page_int < 1:
except ValueError:
raise ValidationError(msg)
except:
if page_int < 1:
raise ValidationError(msg)

View File

@@ -7,7 +7,9 @@ from app.models import EMAIL_TYPE, KEY_TYPE_NORMAL
from app.notifications.process_notifications import persist_notification, send_notification_to_queue
def send_notification_to_service_users(service_id, template_id, personalisation={}, include_user_fields=[]):
def send_notification_to_service_users(service_id, template_id, personalisation=None, include_user_fields=None):
personalisation = personalisation or {}
include_user_fields = include_user_fields or []
template = dao_get_template_by_id(template_id)
service = dao_fetch_service_by_id(service_id)
active_users = dao_fetch_active_users_for_service(service.id)