Skip to content

Commit

Permalink
refactor: fixed a few list -> sequence type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Moe bot authored and jtpavlock committed May 21, 2023
1 parent 4e568e5 commit f2b41b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions moe/duplicate/dup_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Detect and handle duplicates in the library."""

import logging
from typing import Optional
from typing import Optional, Sequence

import sqlalchemy
from sqlalchemy.orm.session import Session
Expand Down Expand Up @@ -70,9 +70,9 @@ def edit_changed_items(session: Session, items: list[LibItem]):
tracks = [item for item in items if isinstance(item, Track)]
extras = [item for item in items if isinstance(item, Extra)]

resolve_duplicates(session, albums) # type: ignore
resolve_duplicates(session, tracks) # type: ignore
resolve_duplicates(session, extras) # type: ignore
resolve_duplicates(session, albums)
resolve_duplicates(session, tracks)
resolve_duplicates(session, extras)


@moe.hookimpl(hookwrapper=True)
Expand All @@ -84,12 +84,12 @@ def edit_new_items(session: Session, items: list[LibItem]):
tracks = [item for item in items if isinstance(item, Track)]
extras = [item for item in items if isinstance(item, Extra)]

resolve_duplicates(session, albums) # type: ignore
resolve_duplicates(session, tracks) # type: ignore
resolve_duplicates(session, extras) # type: ignore
resolve_duplicates(session, albums)
resolve_duplicates(session, tracks)
resolve_duplicates(session, extras)


def resolve_duplicates(session: Session, items: list[LibItem]):
def resolve_duplicates(session: Session, items: Sequence[LibItem]):
"""Search for and resolve any duplicates of items in ``items``."""
log.debug(f"Checking for duplicate items. [{items=}]")

Expand Down Expand Up @@ -141,7 +141,7 @@ def _is_removed(item):


def get_duplicates(
session: Session, item: LibItem, others: Optional[list[LibItem]] = None
session: Session, item: LibItem, others: Optional[Sequence[LibItem]] = None
) -> list[LibItem]:
"""Returns items considered duplicates of ``item``.
Expand Down
4 changes: 2 additions & 2 deletions moe/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import argparse
import logging
from collections import OrderedDict
from typing import Any
from typing import Any, Sequence

from sqlalchemy.orm.session import Session

Expand Down Expand Up @@ -78,7 +78,7 @@ def _parse_args(session: Session, args: argparse.Namespace):
print(item)


def _fmt_infos(items: list[LibItem]):
def _fmt_infos(items: Sequence[LibItem]):
"""Formats information for multiple items together."""
out_str = ""
for item in items:
Expand Down
1 change: 1 addition & 0 deletions moe/util/core/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

__all__ = ["get_match_value", "get_matching_tracks"]

# Custom type declarations used for abbreviated annotations.
TrackMatch = tuple[Optional[MetaTrack], Optional[MetaTrack]]
TrackCoord = tuple[
tuple[int, int], tuple[int, int]
Expand Down

0 comments on commit f2b41b7

Please sign in to comment.