Skip to content

Commit

Permalink
type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
sebdelsol committed Mar 26, 2024
1 parent 6a1d323 commit 174194e
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You need [**Visual Studio**](https://www.visualstudio.com/en-us/downloads/downlo
python -m dev.build [--x86 | --x64 | --both] [--pyinstaller | --mingw] [--nobuild | --noinstaller | --readme] [--upgrade] [--publish]
```
### Upgrade dependencies
It checks for _Nsis_, _Python minor update_ and all _packages dependencies_:
It checks for _Nsis_, _Python minor updates_ and all _packages dependencies_:
```console
python -m dev.upgrade [--x86 | --x64 | --both] [--noeager] [--clean] [--force]
```
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def from_update(cls, update: AppUpdate, exe: Path, python_env: PythonEnv) -> Sel
size=repr_size(exe),
)

def __eq__(self, other: Self) -> bool:
def __eq__(self, other: object) -> bool:
fields = Published._fields
return all(getattr(self, field) == getattr(other, field) for field in fields if field != "exe")

Expand Down
4 changes: 2 additions & 2 deletions dev/tools/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_attr_link(obj: Any, attr: str) -> str:


def _get_exe_kwargs(build: CfgBuild, python_envs: PythonEnvs, publisher: Publisher) -> dict[str, str]:
kwargs = {}
kwargs: dict[str, str] = {}
local_versions = {local_version.bitness: local_version for local_version in publisher.get_local_versions()}
for python_env in python_envs.all:
bitness = python_env.bitness
Expand All @@ -81,7 +81,7 @@ def _get_exe_kwargs(build: CfgBuild, python_envs: PythonEnvs, publisher: Publish


def get_env_kwargs(python_envs: PythonEnvs) -> dict[str, str]:
kwargs = {}
kwargs: dict[str, str] = {}
for bitness, environment in python_envs.declarations.items():
kwargs |= {
f"{bitness}_env_link": _get_attr_link(environment, "path"),
Expand Down
8 changes: 4 additions & 4 deletions dev/tools/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Args(Tap):
class Marker(NamedTuple):
marker: str
replacement: str
count: int
n_marker: int


class MarkedText:
Expand All @@ -40,15 +40,15 @@ def __init__(self, text: str) -> None:

def prepare(self) -> Self:
for i, marker in enumerate(MarkedText.findall(self.text)):
count = self.text.count(marker)
n_marker = self.text.count(marker)
replacement = MarkedText.replacement.format(i)
self.text = self.text.replace(marker, replacement)
self.markers.append(Marker(marker, replacement, count))
self.markers.append(Marker(marker, replacement, n_marker))
return self

def finalize(self, translation: str) -> Optional[str]:
for marker in self.markers:
if marker.count != translation.count(marker.replacement):
if marker.n_marker != translation.count(marker.replacement):
return None
translation = translation.replace(marker.replacement, marker.marker)
return self.ignored(translation).strip()
Expand Down
2 changes: 1 addition & 1 deletion resources/README_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You need [**Visual Studio**](https://www.visualstudio.com/en-us/downloads/downlo
python -m dev.build [--x86 | --x64 | --both] [--pyinstaller | --mingw] [--nobuild | --noinstaller | --readme] [--upgrade] [--publish]
```
### Upgrade dependencies
It checks for _Nsis_, _Python minor update_ and all _packages dependencies_:
It checks for _Nsis_, _Python minor updates_ and all _packages dependencies_:
```console
python -m dev.upgrade [--x86 | --x64 | --both] [--noeager] [--clean] [--force]
```
Expand Down
4 changes: 2 additions & 2 deletions shared/job_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class _Jobs(Generic[T]):
def __init__(self, name: str, check_new: CheckNewsT) -> None:
def __init__(self, name: str, check_new: CheckNewsT[T]) -> None:
self._objs: "multiprocessing.SimpleQueue[T | None]" = multiprocessing.SimpleQueue()
self._stopping = multiprocessing.Event()
self._running = multiprocessing.Event()
Expand Down Expand Up @@ -63,7 +63,7 @@ class JobRunner(Generic[T]):
all following methods should be called from the same process EXCEPT add_job & wait_running
"""

def __init__(self, job: Callable[[T], None], name: str, check_new: CheckNewsT = True) -> None:
def __init__(self, job: Callable[[T], None], name: str, check_new: CheckNewsT[T] = True) -> None:
self._job = job
self._jobs = _Jobs[T](name, check_new)
self._jobs_runner = None
Expand Down
6 changes: 3 additions & 3 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ def set_logging_and_exclude(*log_polluters: str) -> None:
from build_config import Build

class StreamToLogger:
def __init__(self, logger_write: Callable[[str], None]):
def __init__(self, logger_write: Callable[[str], None]) -> None:
self.logger_write = logger_write
self.buf: list[str] = []

def write(self, msg: str):
def write(self, msg: str) -> None:
if msg.endswith("\n"):
self.buf.append(msg.removesuffix("\n"))
self.logger_write("".join(self.buf))
self.buf = []
else:
self.buf.append(msg)

def flush(self):
def flush(self) -> None:
pass

def excepthook(_type: type[BaseException], _value: BaseException, _traceback: TracebackType) -> NoReturn:
Expand Down
2 changes: 1 addition & 1 deletion src/mitm/addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async def response(self, flow: http.HTTPFlow) -> None:
self.mac_cache.stop_all()

# TODO progress for MAC Cache not hiding !! nee to call self.mac_cache.stop_all(), but where?
async def error(self, flow: http.HTTPFlow):
async def error(self, flow: http.HTTPFlow) -> None:
# logger.debug("ERROR %s", flow.request.pretty_url)
if not self.m3u_stream.stop(flow):
if api := await self.api_request(flow):
Expand Down
2 changes: 1 addition & 1 deletion src/mitm/addon/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _log(verb: str, panel: Panel, action: str) -> None:

class AllPanels:
def __init__(self, all_name: AllCategoryName) -> None:
panels = []
panels: list[Panel] = []
if all_name.series:
panels.append(_get_panel(PanelType.SERIES, all_name.series, streams=False))
if all_name.vod:
Expand Down
12 changes: 6 additions & 6 deletions src/mitm/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,17 @@ async def update(self, response: http.Response, page: int) -> bool:
return page >= self.max_pages

@staticmethod
def update_with_loaded(data: list[dict], loaded: MacCacheLoad) -> list[dict]:
def update_with_loaded(data_to_update: list[dict], loaded: MacCacheLoad) -> list[dict]:
if (
(js := get_js(loaded.content, dict))
and (loaded_data := js.get("data"))
and isinstance(loaded_data, list)
and len(loaded_data) > len(data)
and len(loaded_data) > len(data_to_update)
):
ids = {id_: data for data in loaded_data if isinstance(data, dict) and (id_ := data.get("id"))}
ids |= {id_: data for data in data if isinstance(data, dict) and (id_ := data.get("id"))}
data = list(ids.values())
return data
ids |= {id_: data for data in data_to_update if isinstance(data, dict) and (id_ := data.get("id"))}
return list(ids.values())
return data_to_update

def save(self, loaded: Optional[MacCacheLoad]) -> Optional[bool]:
def _save(file: IO[bytes]) -> bool:
Expand Down Expand Up @@ -295,7 +295,7 @@ async def load_response(self, flow: http.HTTPFlow) -> None:
},
)

def inject_all_cached_category(self, flow: http.HTTPFlow):
def inject_all_cached_category(self, flow: http.HTTPFlow) -> None:
# pylint: disable=too-many-boolean-expressions
if (
(response := flow.response)
Expand Down
2 changes: 1 addition & 1 deletion src/sfvip/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def save(self) -> None:
self._shared_self_modified.set()

@property
def shared_self_modified_time(self):
def shared_self_modified_time(self) -> float:
# time when any instance have internally modified the database
with self.lock:
return self._shared_self_modified.time
Expand Down
2 changes: 1 addition & 1 deletion src/sfvip/ui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(
self._bg_separator = bg_separator
self._pad = pad
self._widths = []
self._headers = []
self._headers: list[tk.Label] = []

@staticmethod
def _clear(what: tk.BaseWidget) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/sfvip/utils/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def report_start(self, *_) -> None: ...

def report_postprocess(self) -> None: ...

def report_warning(self, _: str) -> None: ...
def report_warning(self, _) -> None: ...

def report_update(self, decompressed_bytes: str) -> None:
try:
Expand Down

0 comments on commit 174194e

Please sign in to comment.