Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions cleo/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import math

from html.parser import HTMLParser
from typing import Any

from rapidfuzz.distance import Levenshtein

Expand All @@ -13,31 +12,30 @@ def __init__(self) -> None:
super().__init__(convert_charrefs=False)

self.reset()
self.fed = []
self.fed: list[str] = []

def handle_data(self, d) -> None:
def handle_data(self, d: str) -> None:
self.fed.append(d)

def handle_entityref(self, name) -> None:
def handle_entityref(self, name: str) -> None:
self.fed.append(f"&{name};")

def handle_charref(self, name) -> None:
def handle_charref(self, name: str) -> None:
self.fed.append(f"&#{name};")

def get_data(self) -> str:
return "".join(self.fed)


def _strip(value) -> str:
def _strip(value: str) -> str:
s = TagStripper()
s.feed(value)
s.close()

return s.get_data()


def strip_tags(value: Any) -> str:
value = str(value)
def strip_tags(value: str) -> str:
while "<" in value and ">" in value:
new_value = _strip(value)
if value.count("<") == new_value.count("<"):
Expand All @@ -53,7 +51,7 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
Finds names similar to a given command name.
"""
threshold = 1e3
distance_by_name = {}
distance_by_name: dict[str, tuple[int, float]] = {}

for actual_name in names:
# Get Levenshtein distance between the input and each command name
Expand All @@ -74,10 +72,10 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
}

# Display results with shortest distance first
return sorted(distance_by_name, key=distance_by_name.get)
return sorted(distance_by_name, key=distance_by_name.get) # type: ignore[arg-type]


_TIME_FORMATS = [
_TIME_FORMATS: list[tuple[int, str] | tuple[int, str, int]] = [
(0, "< 1 sec"),
(2, "1 sec"),
(59, "secs", 1),
Expand All @@ -90,12 +88,12 @@ def find_similar_names(name: str, names: list[str]) -> list[str]:
]


def format_time(secs: float) -> str:
def format_time(secs: float) -> str: # type: ignore[return]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is getting fixed + refactored in #122, so just ignoring

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anddd i just realized i duplicated some of that pr, oops

for fmt in _TIME_FORMATS:
if secs > fmt[0]:
continue

if len(fmt) == 2:
return fmt[1]

return f"{math.ceil(secs / fmt[2])} {fmt[1]}"
return f"{math.ceil(secs / fmt[2])} {fmt[1]}" # type: ignore
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ show_error_codes = true

[[tool.mypy.overrides]]
module = [
"cleo._utils",
"cleo.application",
"cleo.descriptors.application_description",
"cleo.descriptors.text_descriptor",
Expand Down