Skip to content

Commit 2172423

Browse files
committed
chore(all): fix type hints, add doc strings to all functions
1 parent f42fdca commit 2172423

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

convert.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515

1616

1717
def parse_ofac_xml(path: Path) -> list[DigitalCurrencyAddress]:
18+
"""
19+
Parse out all cryptocurrency addresses from OFAC's SDN XML list.
20+
21+
Params
22+
------
23+
path (Path): Path to the XML file
24+
25+
Returns
26+
-------
27+
list[DigitalCurrencyAddress]: List of parsed cryptocurrency addresses
28+
29+
"""
1830
tree = etree.parse(path)
1931
root = tree.getroot()
2032
entities_parent = root.find("ofac:entities", NS)
@@ -52,7 +64,7 @@ def parse_args() -> argparse.Namespace:
5264
5365
Returns
5466
-------
55-
argparse.Namespace
67+
argparse.Namespace: Args
5668
"""
5769
parser = argparse.ArgumentParser()
5870
parser.add_argument(

util/writers.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,52 @@
22
import json
33
from abc import ABC, abstractmethod
44
from dataclasses import asdict
5+
from pathlib import Path
6+
from typing import Union
57

68
import toml
79

810
from .digital_currency_address import DigitalCurrencyAddress
911

12+
PathOrStrPath = Union[Path, str]
13+
1014

1115
class Writer(ABC):
1216
@abstractmethod
13-
def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None: ...
17+
def write(
18+
self, data: list[DigitalCurrencyAddress], output_path: PathOrStrPath
19+
) -> None:
20+
"""
21+
Format content and write file.
22+
23+
Params
24+
------
25+
data (list[DigitalCurrencyAddress]): List of parsed cryptocurrency address entries
26+
output_path (PathOrStrPath): Path to file to write formatted content
27+
"""
28+
...
1429

1530

1631
class JSONWriter(Writer):
17-
def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
32+
def write(
33+
self, data: list[DigitalCurrencyAddress], output_path: PathOrStrPath
34+
) -> None:
1835
with open(output_path, "w", encoding="utf-8") as f:
1936
json.dump([asdict(entry) for entry in data], f, indent=2)
2037

2138

2239
class TOMLWriter(Writer):
23-
def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
40+
def write(
41+
self, data: list[DigitalCurrencyAddress], output_path: PathOrStrPath
42+
) -> None:
2443
with open(output_path, "w", encoding="utf-8") as f:
2544
toml.dump({"entries": [asdict(entry) for entry in data]}, f)
2645

2746

2847
class CSVWriter(Writer):
29-
def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
48+
def write(
49+
self, data: list[DigitalCurrencyAddress], output_path: PathOrStrPath
50+
) -> None:
3051
if not data:
3152
return
3253

@@ -39,7 +60,9 @@ def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
3960

4061

4162
class TextWriter(Writer):
42-
def write(self, data: list[DigitalCurrencyAddress], output_path: str) -> None:
63+
def write(
64+
self, data: list[DigitalCurrencyAddress], output_path: PathOrStrPath
65+
) -> None:
4366
with open(output_path, "w", encoding="utf-8") as f:
4467
for entry in data:
4568
for key, value in asdict(entry).items():

0 commit comments

Comments
 (0)