From 30765e5c8fd6465286ad6858662966063e8bff48 Mon Sep 17 00:00:00 2001 From: Nick Jackson Date: Thu, 26 Sep 2024 14:59:06 +0100 Subject: [PATCH] WIP: add some typing --- src/ds_caselaw_utils/courts.py | 22 +++++++++++----------- src/ds_caselaw_utils/neutral.py | 3 ++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/ds_caselaw_utils/courts.py b/src/ds_caselaw_utils/courts.py index e1a0884..c6a7b91 100644 --- a/src/ds_caselaw_utils/courts.py +++ b/src/ds_caselaw_utils/courts.py @@ -9,14 +9,14 @@ class Jurisdiction: - def __init__(self, data): + def __init__(self, data) -> None: self.code = data.get("code") self.name = data.get("name") self.prefix = data.get("prefix") class Court: - def __init__(self, data): + def __init__(self, data) -> None: self.code = data.get("code") self.name = data.get("name") self.grouped_name = data.get("grouped_name") or data.get("name") @@ -34,12 +34,12 @@ def get_jurisdiction(self, code): def expand_jurisdictions(self): return [self] + [CourtWithJurisdiction(self, jurisdiction) for jurisdiction in self.jurisdictions] - def __repr__(self): + def __repr__(self) -> str: return self.name class CourtWithJurisdiction(Court): - def __init__(self, court, jurisdiction): + def __init__(self, court, jurisdiction) -> None: self.court = court self.jurisdiction = jurisdiction self.jurisdictions = [] @@ -49,11 +49,11 @@ def code(self): return "/".join((self.court.code, self.jurisdiction.code)) @property - def name(self): + def name(self) -> str: return "%s – %s" % (self.court.name, self.jurisdiction.name) @property - def grouped_name(self): + def grouped_name(self) -> str: return self.court.grouped_name @property @@ -73,11 +73,11 @@ def param_aliases(self): return self.court.param_aliases @property - def start_year(self): + def start_year(self) -> int: return self.court.start_year @property - def end_year(self): + def end_year(self) -> int: return self.court.end_year @property @@ -86,12 +86,12 @@ def jurisdiction_prefix(self): class CourtGroup: - def __init__(self, name, courts): + def __init__(self, name, courts) -> None: self.name = name self.courts = courts @property - def display_heading(self): + def display_heading(self) -> str: return self.name is not None @@ -100,7 +100,7 @@ class CourtNotFoundException(Exception): class CourtsRepository: - def __init__(self, data): + def __init__(self, data) -> None: self._data = data self._byParam = {} self._byCode = {} diff --git a/src/ds_caselaw_utils/neutral.py b/src/ds_caselaw_utils/neutral.py index 411f653..54f0920 100644 --- a/src/ds_caselaw_utils/neutral.py +++ b/src/ds_caselaw_utils/neutral.py @@ -4,6 +4,7 @@ import pathlib import re +from typing import Optional from ruamel.yaml import YAML @@ -13,7 +14,7 @@ citation_data = yaml.load(f) -def neutral_url(citation): +def neutral_url(citation:str) -> Optional[str]: """Given a neutral citation such as `[2020] EAT 17`, return a public-API URL like `/eat/2020/17`, or None if no match is found.