Skip to content

Commit 5e301e6

Browse files
committed
Appease mypy (lots of Lists to Sequences)
1 parent 490c458 commit 5e301e6

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/faff_cli/intent.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from faff_cli.output import create_formatter
1313
from faff_cli.filtering import FilterConfig, apply_filters
1414
from faff_cli.ui import fuzzy_select
15+
from faff_cli.ui.fuzzy_select import FuzzyItem
1516
from faff_cli.start import nicer, nicer_tracker
1617

1718
from faff_core import Workspace, Filter
@@ -665,11 +666,11 @@ def complete(
665666

666667
# Let user select which one to complete
667668
choices = [
668-
{
669-
"name": f"{intent.alias} (missing: {', '.join([f for f in ['role', 'objective', 'action', 'subject'] if not getattr(intent, f)])})",
670-
"value": intent.intent_id,
671-
"decoration": intent.intent_id
672-
}
669+
FuzzyItem(
670+
name=f"{intent.alias} (missing: {', '.join([f for f in ['role', 'objective', 'action', 'subject'] if not getattr(intent, f)])})",
671+
value=intent.intent_id,
672+
decoration=intent.intent_id
673+
)
673674
for intent in incomplete_intents
674675
]
675676

src/faff_cli/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import typer
22
import humanize
3+
from typing import Any
34

45
from faff_cli import log, id, plan, start, timesheet, intent, field, remote, plugin, reflect, session
56
from faff_cli.utils import edit_file
@@ -394,7 +395,7 @@ def status(ctx: typer.Context):
394395

395396
if stale:
396397
# Group by audience
397-
by_audience = {}
398+
by_audience: dict[str, list[Any]] = {}
398399
for ts in stale:
399400
if ts.meta.audience_id not in by_audience:
400401
by_audience[ts.meta.audience_id] = []

src/faff_cli/output.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import json
1111
import sys
12-
from typing import Any, Dict, List, Optional
12+
from typing import Any, Dict, List, Optional, Sequence
1313
from rich.console import Console
1414
from rich.table import Table
1515

@@ -32,7 +32,7 @@ def __init__(self, json_mode: bool = False, plain_mode: bool = False):
3232
def print_table(
3333
self,
3434
data: List[Dict[str, Any]],
35-
columns: List[tuple[str, str, Optional[str]]], # (key, title, style)
35+
columns: Sequence[tuple[str, str, Optional[str]]], # (key, title, style)
3636
title: Optional[str] = None,
3737
total_label: Optional[str] = None,
3838
):
@@ -142,7 +142,10 @@ def print_warning(self, message: str):
142142
if self.plain_mode:
143143
print(formatted, file=sys.stderr)
144144
else:
145-
self.console.print(f"[yellow]{formatted}[/yellow]", file=sys.stderr)
145+
# Rich Console doesn't support file parameter, use stderr console
146+
from rich.console import Console
147+
stderr_console = Console(stderr=True)
148+
stderr_console.print(f"[yellow]{formatted}[/yellow]")
146149

147150
# Private methods
148151

@@ -153,7 +156,7 @@ def _print_json(self, data: Any):
153156
def _print_rich_table(
154157
self,
155158
data: List[Dict[str, Any]],
156-
columns: List[tuple[str, str, Optional[str]]],
159+
columns: Sequence[tuple[str, str, Optional[str]]],
157160
title: Optional[str],
158161
total_label: Optional[str],
159162
):
@@ -182,7 +185,7 @@ def _print_rich_table(
182185
def _print_plain_table(
183186
self,
184187
data: List[Dict[str, Any]],
185-
columns: List[tuple[str, str, Optional[str]]],
188+
columns: Sequence[tuple[str, str, Optional[str]]],
186189
):
187190
"""Print data as tab-separated plain text."""
188191
# Print header

src/faff_cli/ui/fuzzy_select.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from prompt_toolkit.shortcuts import print_formatted_text
1313
from prompt_toolkit.formatted_text import HTML
1414

15-
from typing import Union, Any, Optional, List
15+
from typing import Union, Any, Optional, List, Sequence
1616
from dataclasses import dataclass
1717

1818
from pfzy import fzy_scorer
@@ -32,22 +32,22 @@ class FuzzyItem:
3232
decoration: Optional[str] = None
3333
is_new: bool = False
3434

35-
def is_list_of_strs(items: List[Any]) -> bool:
35+
def is_list_of_strs(items: Sequence[Any]) -> bool:
3636
return all(isinstance(i, str) for i in items)
3737

38-
def is_list_of_dicts(items: List[Any]) -> bool:
38+
def is_list_of_dicts(items: Sequence[Any]) -> bool:
3939
return all(isinstance(i, dict) and "name" in i and "value" in i for i in items)
4040

41-
def is_list_of_dataclasses(items: List[Any]) -> bool:
41+
def is_list_of_dataclasses(items: Sequence[Any]) -> bool:
4242
return all(isinstance(i, FuzzyItem) for i in items)
4343

44-
def normalize_to_fuzzyitems(items: List[Any]) -> List[FuzzyItem]:
44+
def normalize_to_fuzzyitems(items: Sequence[Any]) -> List[FuzzyItem]:
4545
if is_list_of_strs(items):
4646
return [FuzzyItem(name=i, value=i) for i in items]
4747
elif is_list_of_dicts(items):
4848
return [FuzzyItem(name=i["name"], value=i.get("value", i["name"]), decoration=i.get("decoration")) for i in items]
4949
elif is_list_of_dataclasses(items):
50-
return items[:]
50+
return list(items)
5151
else:
5252
raise TypeError("Expected list of str, dicts with name/value, or FuzzyItem instances")
5353

@@ -56,7 +56,7 @@ def slugify_preserving_slashes(path: str, **kwargs) -> str:
5656
return "/".join(slugify(seg, **kwargs) for seg in segments)
5757

5858
def fuzzy_select(prompt: str,
59-
choices: List[Union[str, FuzzyItem]],
59+
choices: Sequence[Union[str, FuzzyItem]],
6060
create_new: bool = True,
6161
max_fraction: float = 0.5,
6262
escapable: bool = True,

0 commit comments

Comments
 (0)