Skip to content

Commit

Permalink
Merge pull request #654 from closeio/black-no-magic-commas
Browse files Browse the repository at this point in the history
No magic commas
  • Loading branch information
tsx authored Feb 1, 2024
2 parents d24d7a8 + 663e388 commit 4b361fb
Show file tree
Hide file tree
Showing 56 changed files with 96 additions and 391 deletions.
7 changes: 1 addition & 6 deletions inbox/api/kellogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,7 @@ def format_messagecategories(messagecategories):
def format_phone_numbers(phone_numbers):
formatted_phone_numbers = []
for number in phone_numbers:
formatted_phone_numbers.append(
{
"type": number.type,
"number": number.number,
}
)
formatted_phone_numbers.append({"type": number.type, "number": number.number})
return formatted_phone_numbers


Expand Down
10 changes: 2 additions & 8 deletions inbox/api/ns_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,7 @@ def status():
else:
account.throttled = False
return g.encoder.jsonify(
{
"sync_status": account.sync_status,
"throttled": account.throttled,
}
{"sync_status": account.sync_status, "throttled": account.throttled}
)


Expand Down Expand Up @@ -2026,10 +2023,7 @@ def sync_deltas():
expand=expand,
)

response = {
"cursor_start": cursor,
"deltas": deltas,
}
response = {"cursor_start": cursor, "deltas": deltas}
if deltas:
end_transaction = g.db_session.query(Transaction).get(end_pointer)
response["cursor_end"] = deltas[-1]["cursor"]
Expand Down
5 changes: 1 addition & 4 deletions inbox/api/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ def update_message(message, request_data, db_session, optimistic):
def update_thread(thread, request_data, db_session, optimistic):
accept_labels = thread.namespace.account.provider == "gmail"

(
unread,
starred,
) = parse_flags(request_data)
(unread, starred) = parse_flags(request_data)
if accept_labels:
labels = parse_labels(request_data, db_session, thread.namespace_id)
else:
Expand Down
6 changes: 1 addition & 5 deletions inbox/auth/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ def authenticate_imap_connection(self, account, conn):
conn.login(account.imap_username, account.imap_password)
except IMAPClient.Error as exc:
if auth_is_invalid(exc):
log.error(
"IMAP login failed",
account_id=account.id,
error=exc,
)
log.error("IMAP login failed", account_id=account.id, error=exc)
raise ValidationError(exc)
elif auth_requires_app_password(exc):
raise AppPasswordError(exc)
Expand Down
4 changes: 1 addition & 3 deletions inbox/auth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ def authenticate_imap_connection(self, account: OAuthAccount, conn: IMAPClient):
raise exc from original_exc

log.warning(
"Error during IMAP XOAUTH2 login",
account_id=account.id,
error=exc,
"Error during IMAP XOAUTH2 login", account_id=account.id, error=exc
)
if not isinstance(exc, ImapSupportDisabledError):
raise # Unknown IMAPClient error, reraise
Expand Down
5 changes: 1 addition & 4 deletions inbox/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ def create_imap_connection(host, port, use_timeout=True):
try:
conn.starttls(context)
except Exception:
log.warning(
"STARTTLS supported but failed.",
exc_info=True,
)
log.warning("STARTTLS supported but failed.", exc_info=True)
raise
else:
raise SSLNotSupportedError("Required IMAP STARTTLS not supported.")
Expand Down
5 changes: 1 addition & 4 deletions inbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def _update_config_from_env(config, env):
srcdir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")

if env in ["prod", "staging"]:
base_cfg_path = [
"/etc/inboxapp/secrets.yml",
"/etc/inboxapp/config.json",
]
base_cfg_path = ["/etc/inboxapp/secrets.yml", "/etc/inboxapp/config.json"]
else:
v = {"env": env, "srcdir": srcdir}
base_cfg_path = [
Expand Down
6 changes: 1 addition & 5 deletions inbox/contacts/carddav.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,7 @@ def get_cards(self, url):
</C:addressbook-query>
"""

response = self.session.request(
"REPORT",
url,
data=payload,
)
response = self.session.request("REPORT", url, data=payload)

response.raise_for_status()
return response.content
Expand Down
7 changes: 1 addition & 6 deletions inbox/contacts/vcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,7 @@ def vcard_from_vobject(vcard):
if isinstance(property_value, list):
property_value = (",").join(property_value)

vdict[property_name].append(
(
property_value,
line.params,
)
)
vdict[property_name].append((property_value, line.params))
return vdict


Expand Down
4 changes: 1 addition & 3 deletions inbox/crispin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,9 +1212,7 @@ def condstore_changed_flags(
self, modseq: int
) -> Dict[int, Union[GmailFlags, Flags]]:
data: Dict[int, Dict[bytes, Any]] = self.conn.fetch(
"1:*",
["FLAGS", "X-GM-LABELS"],
modifiers=[f"CHANGEDSINCE {modseq}"],
"1:*", ["FLAGS", "X-GM-LABELS"], modifiers=[f"CHANGEDSINCE {modseq}"]
)
results: Dict[int, Union[GmailFlags, Flags]] = {}
for uid, ret in data.items():
Expand Down
9 changes: 2 additions & 7 deletions inbox/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ def emit(self, record):
):
return

record.payload_data = {
"fingerprint": event,
"title": event,
}
record.payload_data = {"fingerprint": event, "title": event}

return super().emit(record)

Expand Down Expand Up @@ -110,9 +107,7 @@ def maybe_enable_rollbar():
)

rollbar.init(
ROLLBAR_API_KEY,
application_environment,
allow_logging_basic_config=False,
ROLLBAR_API_KEY, application_environment, allow_logging_basic_config=False
)

rollbar_handler = SyncEngineRollbarHandler()
Expand Down
2 changes: 1 addition & 1 deletion inbox/events/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def sanitize_conference_data(
if entry_point.get("uri")
][:MAX_LIST_LENGTH],
conference_solution=ConferenceSolution(
name=raw_conference_solution.get("name", "")[:MAX_STRING_LENGTH],
name=raw_conference_solution.get("name", "")[:MAX_STRING_LENGTH]
),
)

Expand Down
11 changes: 3 additions & 8 deletions inbox/events/microsoft/graph_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def iter_events(
# The default amount of events per page is 10,
# as we want to do the least
# amount of requests possible we raise it to 500.
"top": "500",
"top": "500"
}

if modified_after:
Expand Down Expand Up @@ -269,10 +269,7 @@ def iter_event_instances(
if fields:
params["$select"] = ",".join(fields)

yield from self._iter(
f"/me/events/{event_id}/instances",
params=params,
)
yield from self._iter(f"/me/events/{event_id}/instances", params=params)

def iter_subscriptions(self) -> Iterable[Dict[str, Any]]:
"""
Expand Down Expand Up @@ -403,9 +400,7 @@ def renew_subscription(
)
assert expiration.tzinfo == pytz.UTC

json = {
"expirationDateTime": format_datetime(expiration),
}
json = {"expirationDateTime": format_datetime(expiration)}

return self.request("PATCH", f"/subscriptions/{subscription_id}", json=json)

Expand Down
7 changes: 1 addition & 6 deletions inbox/events/microsoft/graph_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ class MsGraphDateTimeTimeZone(TypedDict):
"relativeYearly",
]

ICalFreq = Literal[
"DAILY",
"WEEKLY",
"MONTHLY",
"YEARLY",
]
ICalFreq = Literal["DAILY", "WEEKLY", "MONTHLY", "YEARLY"]


class MsGraphRecurrencePattern(TypedDict):
Expand Down
9 changes: 2 additions & 7 deletions inbox/events/microsoft/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ def convert_msgraph_patterned_recurrence_to_ical_rrule(
]
interval = pattern["interval"] * multiplier

rrule: Dict[str, str] = {
"FREQ": freq,
}
rrule: Dict[str, str] = {"FREQ": freq}
if interval != 1:
rrule["INTERVAL"] = str(interval)

Expand Down Expand Up @@ -620,10 +618,7 @@ def validate_event(event: MsGraphEvent) -> bool:


def parse_event(
event: MsGraphEvent,
*,
read_only: bool,
master_event_uid: Optional[str] = None,
event: MsGraphEvent, *, read_only: bool, master_event_uid: Optional[str] = None
) -> Event:
"""
Parse event coming from Microsoft Graph API as ORM object.
Expand Down
4 changes: 1 addition & 3 deletions inbox/ignition.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,5 @@ def reset_invalid_autoincrements(engine, schema, key, dry_run=True):

# these are _required_. nylas shouldn't start if these aren't present.
redis_txn = redis.Redis(
config["TXN_REDIS_HOSTNAME"],
int(config["REDIS_PORT"]),
db=config["TXN_REDIS_DB"],
config["TXN_REDIS_HOSTNAME"], int(config["REDIS_PORT"]), db=config["TXN_REDIS_DB"]
)
7 changes: 1 addition & 6 deletions inbox/mailsync/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ def build_metadata():
_, build_id = f.readline().rstrip("\n").split()
build_id = build_id[1:-1] # Remove first and last single quotes.
_, git_commit = f.readline().rstrip("\n").split()
return jsonify(
{
"build_id": build_id,
"git_commit": git_commit,
}
)
return jsonify({"build_id": build_id, "git_commit": git_commit})


class _QuietHandler(WSGIRequestHandler):
Expand Down
5 changes: 1 addition & 4 deletions inbox/mailsync/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def __init__(
SYNC_EVENT_QUEUE_NAME.format(self.process_identifier)
)
self.queue_group = EventQueueGroup(
[
shared_sync_event_queue_for_zone(self.zone),
self.private_queue,
]
[shared_sync_event_queue_for_zone(self.zone), self.private_queue]
)

self.stealing_enabled = config.get("SYNC_STEAL_ACCOUNTS", True)
Expand Down
8 changes: 1 addition & 7 deletions inbox/models/backends/imap.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,7 @@ def categories(self) -> Set[Category]:
categories.add(self.folder.category)
return categories

__table_args__ = (
UniqueConstraint(
"folder_id",
"msg_uid",
"account_id",
),
)
__table_args__ = (UniqueConstraint("folder_id", "msg_uid", "account_id"),)


# make pulling up all messages in a given folder fast
Expand Down
5 changes: 1 addition & 4 deletions inbox/sendmail/smtp/postel.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ def _upgrade_connection(self):
try:
self.connection.starttls()
except ssl.SSLError as e:
log.warning(
"STARTTLS supported but failed.",
exc_info=True,
)
log.warning("STARTTLS supported but failed.", exc_info=True)
msg = _transform_ssl_error(e.strerror)
raise SendMailException(msg, 503)
else:
Expand Down
17 changes: 4 additions & 13 deletions inbox/sendmail/smtp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,17 @@
"4.3.5": (429, "Mail server temporarily rejected message."),
"4.7.1": (429, "Mail server temporarily rejected message."),
},
452: {
"4.5.3": (402, "Your message has too many recipients"),
},
452: {"4.5.3": (402, "Your message has too many recipients")},
454: {
"4.7.0": (
429,
"Cannot authenticate due to temporary system problem. Try again later.",
)
},
522: {
"5.7.1": (402, "Recipient address rejected."),
},
530: {
"5.7.0": (402, "Recipient address rejected"),
},
522: {"5.7.1": (402, "Recipient address rejected.")},
530: {"5.7.0": (402, "Recipient address rejected")},
535: {
"5.7.1": (
429,
"Please log in to Gmail with your web browser and try again.",
),
"5.7.1": (429, "Please log in to Gmail with your web browser and try again.")
},
550: {
"5.1.1": (
Expand Down
12 changes: 3 additions & 9 deletions inbox/transactions/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,19 @@ def __init__(self, poll_interval=30, chunk_size=DOC_UPLOAD_CHUNK_SIZE):
Greenlet.__init__(self)

def _report_batch_upload(self):
metric_names = [
"contacts_search_index.transactions.batch_upload",
]
metric_names = ["contacts_search_index.transactions.batch_upload"]

for metric in metric_names:
statsd_client.incr(metric)

def _report_transactions_latency(self, latency):
metric_names = [
"contacts_search_index.transactions.latency",
]
metric_names = ["contacts_search_index.transactions.latency"]

for metric in metric_names:
statsd_client.timing(metric, latency)

def _publish_heartbeat(self):
metric_names = [
"contacts_search_index.heartbeat",
]
metric_names = ["contacts_search_index.heartbeat"]

for metric in metric_names:
statsd_client.incr(metric)
Expand Down
8 changes: 1 addition & 7 deletions inbox/util/blockstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@

def _data_file_directory(h):
return os.path.join(
config.get_required("MSG_PARTS_DIRECTORY"),
h[0],
h[1],
h[2],
h[3],
h[4],
h[5],
config.get_required("MSG_PARTS_DIRECTORY"), h[0], h[1], h[2], h[3], h[4], h[5]
)


Expand Down
5 changes: 1 addition & 4 deletions inbox/util/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ class MockDNSResolver:
def __init__(self):
self._registry: Dict[
Literal["mx", "ns"], Dict[str, Union[Dict[str, str], List[str]]]
] = {
"mx": {},
"ns": {},
}
] = {"mx": {}, "ns": {}}

def _load_records(self, filename):
self._registry = json.loads(get_data(filename))
Expand Down
3 changes: 1 addition & 2 deletions inbox/webhooks/microsoft_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def event_update(calendar_public_id):


def handle_event_deletions(
calendar: Calendar,
change_notifications: List[MsGraphChangeNotification],
calendar: Calendar, change_notifications: List[MsGraphChangeNotification]
) -> None:
deleted_event_uids = [
change_notification["resourceData"]["id"]
Expand Down
Loading

0 comments on commit 4b361fb

Please sign in to comment.