Skip to content

Commit

Permalink
Merge pull request #1001 from closeio/restore-mypy
Browse files Browse the repository at this point in the history
Restore running `mypy` in CI
  • Loading branch information
neob91-close authored Dec 16, 2024
2 parents 1ed7d96 + a10ee49 commit f6f2371
Show file tree
Hide file tree
Showing 370 changed files with 3,357 additions and 2,115 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ jobs:
- name: Ruff
run: ruff check --no-cache --output-format github .

- name: Install production requirements (for Mypy)
run: |
# Mypy needs production packages for typechecking
pip install --no-deps -r requirements/requirements-prod.txt
- name: Mypy
run: mypy

check-compiled-requirements:
runs-on: ubuntu-24.04
if: ${{ !contains(github.event.head_commit.message, '#notests') }}
Expand Down
8 changes: 4 additions & 4 deletions bin/backfix-duplicate-categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from itertools import chain

import click
from sqlalchemy import func
from sqlalchemy.sql import and_, exists
from sqlalchemy import func # type: ignore[import-untyped]
from sqlalchemy.sql import and_, exists # type: ignore[import-untyped]

from inbox.error_handling import maybe_enable_rollbar
from inbox.ignition import engine_manager
Expand All @@ -20,7 +20,7 @@
log = get_logger(purpose="duplicate-category-backfill")


def backfix_shard(shard_id, dry_run) -> None:
def backfix_shard(shard_id, dry_run) -> None: # type: ignore[no-untyped-def]
categories_to_fix = []
with session_scope_by_shard_id(shard_id) as db_session:
# 'SELECT id FROM <table> GROUP BY <x>' does not select _all_ of the
Expand Down Expand Up @@ -188,7 +188,7 @@ def backfix_shard(shard_id, dry_run) -> None:
@click.command()
@click.option("--shard-id", type=int, default=None)
@click.option("--dry-run", is_flag=True)
def main(shard_id, dry_run) -> None:
def main(shard_id, dry_run) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

if shard_id is not None:
Expand Down
6 changes: 3 additions & 3 deletions bin/backfix-generic-imap-separators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@click.option("--min-id", type=int, default=None)
@click.option("--max-id", type=int, default=None)
@click.option("--shard-id", type=int, default=None)
def main(min_id, max_id, shard_id) -> None:
def main(min_id, max_id, shard_id) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

generic_accounts = []
Expand All @@ -37,12 +37,12 @@ def main(min_id, max_id, shard_id) -> None:
)

if min_id is not None:
generic_accounts = generic_accounts.filter(
generic_accounts = generic_accounts.filter( # type: ignore[attr-defined]
GenericAccount.id > min_id
)

if max_id is not None:
generic_accounts = generic_accounts.filter(
generic_accounts = generic_accounts.filter( # type: ignore[attr-defined]
GenericAccount.id <= max_id
)

Expand Down
10 changes: 5 additions & 5 deletions bin/check-attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from collections import defaultdict

import click
from sqlalchemy import true
from sqlalchemy.sql.expression import func
from sqlalchemy import true # type: ignore[import-untyped]
from sqlalchemy.sql.expression import func # type: ignore[import-untyped]

from inbox.error_handling import maybe_enable_rollbar
from inbox.logging import configure_logging, get_logger
Expand All @@ -20,8 +20,8 @@
NUM_MESSAGES = 10


def process_account(account_id): # noqa: ANN201
ret = defaultdict(int)
def process_account(account_id): # type: ignore[no-untyped-def] # noqa: ANN201
ret = defaultdict(int) # type: ignore[var-annotated]

try:
with session_scope(account_id) as db_session:
Expand Down Expand Up @@ -67,7 +67,7 @@ def process_account(account_id): # noqa: ANN201

@click.command()
@click.option("--num-accounts", type=int, default=1500)
def main(num_accounts) -> None:
def main(num_accounts) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

with global_session_scope() as db_session:
Expand Down
7 changes: 5 additions & 2 deletions bin/clear-all-heartbeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@click.option("--host", "-h", type=str, default="localhost")
@click.option("--port", "-p", type=int, default=6379)
@click.option("--database", "-d", type=int, default=STATUS_DATABASE)
def main(host, port, database) -> None:
def main(host, port, database) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

connection_pool = BlockingConnectionPool(
Expand All @@ -36,7 +36,10 @@ def main(host, port, database) -> None:

count = 0
for name in client.scan_iter(count=100):
if name == "ElastiCacheMasterReplicationTimestamp":
if (
name # type: ignore[comparison-overlap]
== "ElastiCacheMasterReplicationTimestamp"
):
continue
batch_client.delete(name)
count += 1
Expand Down
5 changes: 4 additions & 1 deletion bin/clear-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def main() -> None:
default=False,
)
args = parser.parse_args()
from inbox.ignition import init_db, main_engine
from inbox.ignition import ( # type: ignore[attr-defined]
init_db,
main_engine,
)

maybe_enable_rollbar()

Expand Down
8 changes: 6 additions & 2 deletions bin/clear-heartbeat-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
@click.option("--account-id", "-a", type=int, required=True)
@click.option("--folder-id", "-f", type=int)
@click.option("--device-id", "-d", type=int)
def main(host, port, account_id, folder_id, device_id) -> None:
def main( # type: ignore[no-untyped-def]
host, port, account_id, folder_id, device_id
) -> None:
maybe_enable_rollbar()

print("Clearing heartbeat status...")
n = clear_heartbeat_status(account_id, folder_id, device_id, host, port)
n = clear_heartbeat_status( # type: ignore[call-arg]
account_id, folder_id, device_id, host, port
)
print(f"{n} folders cleared.")
exit(0)

Expand Down
4 changes: 2 additions & 2 deletions bin/clear-kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import click

from inbox.error_handling import maybe_enable_rollbar
from inbox.heartbeat.config import (
from inbox.heartbeat.config import ( # type: ignore[attr-defined]
REPORT_DATABASE,
STATUS_DATABASE,
_get_redis_client,
Expand All @@ -16,7 +16,7 @@
@click.command()
@click.option("--host", "-h", type=str)
@click.option("--port", "-p", type=int, default=6379)
def main(host, port) -> None:
def main(host, port) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

if host:
Expand Down
2 changes: 1 addition & 1 deletion bin/correct-autoincrements.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@click.command()
@click.option("--dry-run", is_flag=True)
def reset_db(dry_run) -> None:
def reset_db(dry_run) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

database_hosts = config.get_required("DATABASE_HOSTS")
Expand Down
4 changes: 2 additions & 2 deletions bin/create-db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import alembic.command
import alembic.config
import click
import sqlalchemy
import sqlalchemy # type: ignore[import-untyped]

from inbox.config import config
from inbox.error_handling import maybe_enable_rollbar
Expand All @@ -21,7 +21,7 @@
help="Limit database initialization to only one host / set of shards",
)
@click.option("--host-ip", default=None)
def main(target_hostname, host_ip) -> None:
def main(target_hostname, host_ip) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

database_hosts = config.get_required("DATABASE_HOSTS")
Expand Down
2 changes: 1 addition & 1 deletion bin/create-encryption-keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def main() -> None:
from inbox.config import config, secrets_path
from inbox.config import config, secrets_path # type: ignore[attr-defined]

maybe_enable_rollbar()

Expand Down
8 changes: 5 additions & 3 deletions bin/create-event-contact-associations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


import click
from sqlalchemy import asc
from sqlalchemy import asc # type: ignore[import-untyped]

from inbox.contacts.processing import update_contacts_from_event
from inbox.error_handling import maybe_enable_rollbar
Expand All @@ -19,7 +19,9 @@
log = get_logger(purpose="create-event-contact-associations")


def process_shard(shard_id, dry_run, id_start: int = 0) -> None:
def process_shard( # type: ignore[no-untyped-def]
shard_id, dry_run, id_start: int = 0
) -> None:
# At 500K events, we need to process 6 events per second to finish within a day.
batch_size = 100
rps = 6 / batch_size
Expand Down Expand Up @@ -95,7 +97,7 @@ def process_shard(shard_id, dry_run, id_start: int = 0) -> None:
@click.option("--shard-id", type=int, default=None)
@click.option("--id-start", type=int, default=0)
@click.option("--dry-run", is_flag=True)
def main(shard_id, id_start, dry_run) -> None:
def main(shard_id, id_start, dry_run) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

if shard_id is not None:
Expand Down
8 changes: 6 additions & 2 deletions bin/delete-account-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
@click.option("--dry-run", is_flag=True)
@click.option("--yes", is_flag=True)
@click.option("--throttle", is_flag=True)
def delete_account_data(account_id, dry_run, yes, throttle) -> int | None:
def delete_account_data( # type: ignore[no-untyped-def]
account_id, dry_run, yes, throttle
) -> int | None:
maybe_enable_rollbar()

with session_scope(account_id) as db_session:
Expand Down Expand Up @@ -63,7 +65,9 @@ def delete_account_data(account_id, dry_run, yes, throttle) -> int | None:
)
)

answer = raw_input(question).strip().lower() # noqa: F821
answer = (
raw_input(question).strip().lower() # type: ignore[name-defined] # noqa: F821
)

if answer != "yes":
print("Will NOT delete, goodbye.")
Expand Down
6 changes: 4 additions & 2 deletions bin/delete-marked-accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@click.command()
@click.option("--throttle", is_flag=True)
@click.option("--dry-run", is_flag=True)
def run(throttle, dry_run) -> None:
def run(throttle, dry_run) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

print("Python", sys.version, file=sys.stderr)
Expand All @@ -42,7 +42,9 @@ def run(throttle, dry_run) -> None:
executor.submit(delete_account_data, host, throttle, dry_run)


def delete_account_data(host, throttle, dry_run) -> None:
def delete_account_data( # type: ignore[no-untyped-def]
host, throttle, dry_run
) -> None:
while True:
for shard in host["SHARDS"]:
# Ensure shard is explicitly not marked as disabled
Expand Down
2 changes: 1 addition & 1 deletion bin/detect-missing-sync-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import click
from sqlalchemy.orm import load_only
from sqlalchemy.orm import load_only # type: ignore[import-untyped]

from inbox.error_handling import maybe_enable_rollbar
from inbox.models.account import Account
Expand Down
2 changes: 1 addition & 1 deletion bin/get-accounts-for-host.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@click.command()
@click.argument("hostname")
def main(hostname) -> None:
def main(hostname) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

with global_session_scope() as db_session:
Expand Down
14 changes: 11 additions & 3 deletions bin/get-id.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
@click.option("--type", "-t", type=str, required=True)
@click.option("--id", type=str, default=None)
@click.option("--public-id", type=str, default=None)
def main(type, id, public_id) -> None:
def main(type, id, public_id) -> None: # type: ignore[no-untyped-def]
maybe_enable_rollbar()

type = type.lower() # noqa: A001
Expand All @@ -55,11 +55,19 @@ def main(type, id, public_id) -> None:
with global_session_scope() as db_session:
if public_id:
obj = (
db_session.query(cls).filter(cls.public_id == public_id).one()
db_session.query(cls)
.filter(
cls.public_id == public_id # type: ignore[attr-defined]
)
.one()
)
print(obj.id)
elif id:
obj = db_session.query(cls).filter(cls.id == id).one()
obj = (
db_session.query(cls)
.filter(cls.id == id) # type: ignore[attr-defined]
.one()
)
print(obj.public_id)


Expand Down
22 changes: 16 additions & 6 deletions bin/get-object.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
)

try:
from inbox.models.backends.eas import EASFolderSyncStatus
from inbox.models.backends.eas import ( # type: ignore[import-not-found]
EASFolderSyncStatus,
)

cls_for_type["easfoldersyncstatus"] = EASFolderSyncStatus
except ImportError:
Expand All @@ -48,7 +50,9 @@
@click.option("--account-id", type=str, default=None)
@click.option("--namespace-id", type=str, default=None)
@click.option("--readwrite", is_flag=True, default=False)
def main(type, id, public_id, account_id, namespace_id, readwrite) -> None:
def main( # type: ignore[no-untyped-def]
type, id, public_id, account_id, namespace_id, readwrite
) -> None:
maybe_enable_rollbar()

type = type.lower() # noqa: A001
Expand All @@ -67,14 +71,20 @@ def main(type, id, public_id, account_id, namespace_id, readwrite) -> None:
qu = db_session.query(cls)

if public_id:
qu = qu.filter(cls.public_id == public_id)
qu = qu.filter(
cls.public_id == public_id # type: ignore[attr-defined]
)
elif id:
qu = qu.filter(cls.id == id)
qu = qu.filter(cls.id == id) # type: ignore[attr-defined]

if account_id:
qu = qu.filter(cls.account_id == account_id)
qu = qu.filter(
cls.account_id == account_id # type: ignore[attr-defined]
)
elif namespace_id:
qu = qu.filter(cls.namespace_id == namespace_id)
qu = qu.filter(
cls.namespace_id == namespace_id # type: ignore[attr-defined]
)

obj = qu.one() # noqa: F841

Expand Down
Loading

0 comments on commit f6f2371

Please sign in to comment.