Skip to content

Commit

Permalink
Fix the type hints to satisfy flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkovtsev committed Dec 21, 2022
1 parent 1c37a05 commit de85c50
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion server/athenian/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ async def _extract_api_key(self, token: str, request: AthenianWebRequest) -> Tup
return user, await request.sdb.fetch_val(
select([UserAccount.account_id]).where(UserAccount.user_id == user),
)
kms = request.app["kms"] # type: AthenianKMS
kms: AthenianKMS = request.app["kms"]
if kms is None:
raise AuthenticationProblem(
status=HTTPStatus.UNAUTHORIZED,
Expand Down
4 changes: 2 additions & 2 deletions server/athenian/api/controllers/histograms_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ async def calculate_for_set_histograms(filter_checks: FilterChecks):
]
total_group_suites = my_suite_counts.sum()
for suite_size_group_index, suite_size_group in enumerate(lines_group):
group_for_set = (
group_for_set: ForSetCodeChecks = (
for_set.select_pushers_group(pushers_group_index)
.select_repogroup(repos_group_index)
.select_lines(lines_index)
) # type: ForSetCodeChecks
)
if filt.split_by_check_runs:
suite_size = suite_sizes[suite_size_group_index]
group_suites_count_ratio = (
Expand Down
4 changes: 2 additions & 2 deletions server/athenian/api/controllers/metrics_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,15 @@ async def calc_code_bypassing_prs(request: AthenianWebRequest, body: dict) -> we
calculator = make_calculator(
filt.account, meta_ids, request.mdb, request.pdb, request.rdb, request.cache,
)
stats = await calculator.calc_code_metrics_github(
stats: list[CodeStats] = await calculator.calc_code_metrics_github(
FilterCommitsProperty.BYPASSING_PRS,
time_intervals,
[r.unprefixed for r in repos],
with_author,
with_committer,
filt.only_default_branch,
prefixer,
) # type: list[CodeStats]
)
model = [
CodeBypassingPRsMeasurement(
date=(d - tzoffset).date(),
Expand Down
4 changes: 2 additions & 2 deletions server/athenian/api/defer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from asyncio import Event, current_task, ensure_future, gather, shield, sleep
from contextvars import ContextVar
import logging
from typing import Awaitable, Coroutine, List
from typing import Awaitable, Coroutine

from aiohttp import web
import asyncpg
Expand Down Expand Up @@ -47,7 +47,7 @@ def launch_defer(delay: float, name: str, detached: bool = False) -> None:
if launch_event.is_set():
log.warning("launch_defer() called multiple times")
return
transaction_ptr = _defer_transaction.get() # type: List[Transaction]
transaction_ptr: list[Transaction] = _defer_transaction.get()
deferred_count_ptr = _defer_counter.get()
explicit_launch = _defer_explicit.get()
except LookupError:
Expand Down
4 changes: 2 additions & 2 deletions server/athenian/api/experiments/idmatching/make_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def main():
args = parse_args()
bar = tqdm(total=11)
engine = create_engine(args.metadata_db)
mdb = sessionmaker(bind=engine)() # type: Session
mdb: Session = sessionmaker(bind=engine)()
bar.update(1)
engine = create_engine(args.state_db)
sdb = sessionmaker(bind=engine)() # type: Session
sdb: Session = sessionmaker(bind=engine)()
bar.update(1)
meta_id = (
sdb.query(AccountGitHubAccount.id)
Expand Down
2 changes: 1 addition & 1 deletion server/athenian/api/experiments/indexing/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def virtual_indexes(df):
]:
print(f"Building for layer {layer_level}...")
df_level = df.groupby(col).agg({"values": sum}).reset_index()
df_level["values"] = df_level["values"].apply(lambda l: list(set(l)))
df_level["values"] = df_level["values"].apply(lambda lv: list(set(lv)))
df_level = df_level.rename(columns={col: "timestamp"})

layers[layer_level] = layer(df_level)
Expand Down
5 changes: 2 additions & 3 deletions server/athenian/api/models/precomputed/schema_monitor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import asyncio
from collections import defaultdict
import logging
from typing import List, Optional

import aiohttp
from alembic import script
Expand All @@ -16,7 +15,7 @@ def schedule_pdb_schema_check(
pdb: morcilla.Database,
app: aiohttp.web.Application,
interval: float = 15 * 60,
) -> List[asyncio.Task]:
) -> list[asyncio.Task]:
"""
Execute the precomputed DB schema version check every `interval` seconds.
Expand All @@ -27,7 +26,7 @@ def schedule_pdb_schema_check(
log = logging.getLogger("%s.scheduled_pdb_schema_check" % metadata.__package__)
req_rev = script.ScriptDirectory(str(template.parent)).get_current_head()
sql = MigrationContext.configure(url=str(pdb.url), opts={"as_sql": True})._version.select()
task_box = [None] # type: List[Optional[asyncio.Task]]
task_box: list[asyncio.Task | None] = [None]

async def pdb_schema_check_callback() -> None:
await asyncio.sleep(interval)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ async def test_deployment_metrics_calculators_smoke(
default_branches,
):
for i in range(2):
calc = metrics_calculator_factory(
1, (6366825,), with_cache=True,
) # type: MetricEntriesCalculator
calc: MetricEntriesCalculator = metrics_calculator_factory(1, (6366825,), with_cache=True)
if i == 1:
calc._mdb = None
calc._rdb = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def gen_dummy_df(dt: datetime) -> pd.DataFrame:


async def test_load_store_precomputed_done_smoke(pdb, pr_samples, done_prs_facts_loader, prefixer):
samples = pr_samples(200) # type: Sequence[PullRequestFacts]
samples: Sequence[PullRequestFacts] = pr_samples(200)
for i in range(1, 6):
# merged but unreleased
kwargs = dict(**samples[-i])
Expand Down
2 changes: 1 addition & 1 deletion server/tests/internal/miners/jira/test_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async def test_fetch_released_prs_release_settings_events(
done_prs_facts_loader,
prefixer,
):
samples = pr_samples(12) # type: Sequence[PullRequestFacts]
samples: Sequence[PullRequestFacts] = pr_samples(12)
names = ["one", "two", "three"]
settings = ReleaseSettings(
{
Expand Down

0 comments on commit de85c50

Please sign in to comment.