Skip to content

Commit

Permalink
Some typing information additions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwax committed Jul 3, 2016
1 parent a3b68f7 commit e4ce97c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions mtg_ssm/mtg/card_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def card_name_to_printing_key(printing):
class CardDb:
"""Card database, containing information and indexes for magic cards."""

def __init__(self, mtg_json_data=None, include_online_only=False):
self.name_to_card = {}
self.code_to_card_set = {}
self.setname_to_card_set = {}
self.id_to_printing = {}

self.cards = None
self.card_sets = None
def __init__(self, mtg_json_data=None, include_online_only=False) -> None:
self.name_to_card = {} # type: Mapping[str, models.Card]
self.code_to_card_set = {} # type: Mapping[str, models.CardSet]
self.setname_to_card_set = {} # type: Mapping[str, models.CardSet]
self.id_to_printing = {} # type: Mapping[str, models.CardPrinting]

self.cards = None # type: List[models.Card]
self.card_sets = None # type: List[models.CardSet]

self.set_code_to_printings = None
self.card_name_to_printings = None
Expand Down
6 changes: 3 additions & 3 deletions mtg_ssm/mtg/counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import collections
import enum
from typing import Mapping

NAME_SUBSTITUTIONS = [
('Ae', 'Æ'),
Expand All @@ -44,7 +45,7 @@ class CountTypes(enum.Enum):
foils = 'foils'


def new_print_counts():
def new_print_counts() -> Mapping[str, Mapping[CountTypes, int]]:
"""Get an appropriate defaultdict set up for use ase print counts."""
return collections.defaultdict(
lambda: collections.defaultdict(int))
Expand Down Expand Up @@ -88,8 +89,7 @@ def coerce_card_row(card_count):

def aggregate_print_counts(cdb, card_rows, strict):
"""Given a card database Iterable[card_row], return print_counts"""
print_counts = collections.defaultdict(
lambda: collections.defaultdict(int))
print_counts = new_print_counts()
for card_row in card_rows:
card_row = coerce_card_row(card_row)
printing_id = card_row.get('id')
Expand Down
4 changes: 2 additions & 2 deletions mtg_ssm/mtg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def __init__(self, card_db, set_code, card_data):
self.artist = card_data['artist']

if self.set_number is None:
self.set_integer = None
self.set_variant = None
self.set_integer = None # type: int
self.set_variant = None # type: str
else:
self.set_integer = int(self.set_number.strip(VARIANT_CHARS))
self.set_variant = self.set_number.strip(string.digits) or None
Expand Down
2 changes: 1 addition & 1 deletion mtg_ssm/serialization/deckbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(1, 20, 'Gateway'),
(21, 100, 'Wizards Play Network'),
],
}
} # type: Mapping[str, List[Tuple[int, int, str]]]
MTGJSON_TO_DECKBOX_SETNAME = {
s: k
for k, v in DECKBOX_EDITION_TO_RANGE_AND_SETNAMES.items()
Expand Down
6 changes: 4 additions & 2 deletions mtg_ssm/serialization/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ def __init__(self, cdb: card_db.CardDb) -> None:
self.cdb = cdb

@property
@classmethod
@abc.abstractmethod
def extension(self) -> str:
def extension(cls) -> str:
"""Registered file extension, excluding '.' """

@property
@classmethod
@abc.abstractmethod
def dialect(self) -> str:
def dialect(cls) -> str:
"""Registered dialect name.
Note: a dialect that matches the extension will be considered the
Expand Down

0 comments on commit e4ce97c

Please sign in to comment.