From 4d93c08e447f8d1d8d2a3206267856014adf4de7 Mon Sep 17 00:00:00 2001 From: alyx Date: Fri, 24 Nov 2023 02:22:27 -0500 Subject: Wow, I forgot how to write python lmao --- src/bbss/buttons.py | 3 ++- src/bbss/lists.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/bbss/buttons.py b/src/bbss/buttons.py index 63de4d1..633dc0b 100644 --- a/src/bbss/buttons.py +++ b/src/bbss/buttons.py @@ -1,5 +1,6 @@ from .lists import ListFile, ListFileEntry, ListFileIterator from dataclasses import dataclass +from typing import cast import requests @dataclass(frozen=True) @@ -14,7 +15,7 @@ class ButtonListFileEntry(ListFileEntry): class ButtonListFileIterator(ListFileIterator): def __next__(self) -> ButtonListFileEntry: - return super().__next__() + return cast(ButtonListFileEntry, super().__next__()) @dataclass(frozen=True) class ButtonListFile(ListFile): diff --git a/src/bbss/lists.py b/src/bbss/lists.py index 3d4779e..234d0f8 100644 --- a/src/bbss/lists.py +++ b/src/bbss/lists.py @@ -1,11 +1,12 @@ from dataclasses import dataclass from collections.abc import Iterable, Iterator +from typing import Optional import requests @dataclass(frozen=True) class ListFileEntry: entry: str - comment: str + comment: Optional[str] class ListFileIterator(Iterator[ListFileEntry]): def __init__(self, entries: list[ListFileEntry]): @@ -23,13 +24,13 @@ class ListFile(Iterable[ListFileEntry]): self._contents = contents acc = [] comment_acc = "" - for line in str.splitlines(): + for line in contents.splitlines(): if line.startswith("#"): continue elif line.startswith("##"): - comment_acc += line[2:].split() + comment_acc += line[2:].strip() else: - acc += ListFileEntry(comment = comment_acc if comment_acc else None, entry = line) + acc.append(ListFileEntry(comment = comment_acc if comment_acc else None, entry = line)) self._entries = acc -- cgit v1.2.3-70-g09d2