fix(types): resolve pre-existing basedpyright errors in tests

Fix ~790 basedpyright errors across the test suite:
- Type stub subclasses of real production classes with super().__init__()
- Add missing generic type arguments and Dict[str, Any] annotations
- Add None guards before subscript/member access
- Adapt tests to production API changes (removed dead handlers,
  PersistentModelCache.get_default, _i18n_filter_added location)
This commit is contained in:
Will Miao
2026-08-08 20:12:59 +08:00
parent 8e724538bd
commit d2f955266d
95 changed files with 953 additions and 666 deletions

View File

@@ -31,7 +31,7 @@ class _DummyModel:
return self
def test_nunchaku_load_lora_legacy_fallback(monkeypatch, caplog):
import folder_paths
import folder_paths # pyright: ignore[reportMissingImports]
import copy
dummy_model = _DummyModel()
@@ -59,7 +59,7 @@ def test_nunchaku_load_lora_legacy_fallback(monkeypatch, caplog):
assert result_model.model.diffusion_model.loras[0][1] == 0.8
def test_nunchaku_load_lora_new_logic(monkeypatch):
import folder_paths
import folder_paths # pyright: ignore[reportMissingImports]
import os
dummy_model = _DummyModel()

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
from typing import Any, cast
from py.nodes.prompt import PromptLM
from py.nodes.text import TextLM
@@ -49,7 +51,7 @@ def test_prompt_lm_input_types_expose_input_only_seed():
assert seed_type == "INT"
assert seed_options["forceInput"] is True
assert "wildcard generation" in seed_options["tooltip"]
assert "wildcard generation" in cast(Any, seed_options)["tooltip"]
def test_text_lm_input_types_expose_input_only_seed():
@@ -58,7 +60,7 @@ def test_text_lm_input_types_expose_input_only_seed():
assert seed_type == "INT"
assert seed_options["forceInput"] is True
assert "wildcard generation" in seed_options["tooltip"]
assert "wildcard generation" in cast(Any, seed_options)["tooltip"]
def test_text_lm_is_changed_forces_rerun_without_seed_when_text_is_dynamic():

View File

@@ -1,8 +1,9 @@
import json
import os
from typing import Any, cast
import numpy as np
import piexif
import piexif # pyright: ignore[reportMissingTypeStubs]
from PIL import Image
from py.services.service_registry import ServiceRegistry
@@ -136,7 +137,8 @@ def test_save_image_skips_jpeg_metadata_when_disabled(monkeypatch, tmp_path):
image_path = tmp_path / "sample_00001_.jpg"
exif_dict = piexif.load(str(image_path))
assert piexif.ExifIFD.UserComment not in exif_dict.get("Exif", {})
exif_ifd = exif_dict.get("Exif", {}) or {}
assert piexif.ExifIFD.UserComment not in exif_ifd
def test_save_image_skips_webp_metadata_when_disabled(monkeypatch, tmp_path):
@@ -154,7 +156,8 @@ def test_save_image_skips_webp_metadata_when_disabled(monkeypatch, tmp_path):
image_path = tmp_path / "sample_00001_.webp"
exif_dict = piexif.load(str(image_path))
assert piexif.ExifIFD.UserComment not in exif_dict.get("Exif", {})
exif_ifd = exif_dict.get("Exif", {}) or {}
assert piexif.ExifIFD.UserComment not in exif_ifd
def test_process_image_returns_passthrough_result_and_ui_images(monkeypatch, tmp_path):
@@ -474,25 +477,34 @@ class TestParameterDefaultConsistency:
input_types = SaveImageLM.INPUT_TYPES()
optional = input_types["optional"]
assert optional["webp_method"][1]["default"] == 6
assert SaveImageLM.save_images.__defaults__[4] == 6 # positional: webp_method=6 is at index 4
assert SaveImageLM.process_image.__defaults__[6] == 6
widget_spec = cast(Any, optional["webp_method"])
assert widget_spec[1]["default"] == 6
save_defaults = cast(tuple[Any, ...], SaveImageLM.save_images.__defaults__ or ())
process_defaults = cast(tuple[Any, ...], SaveImageLM.process_image.__defaults__ or ())
assert save_defaults[4] == 6 # positional: webp_method=6 is at index 4
assert process_defaults[6] == 6
def test_jpeg_subsampling_defaults_are_consistent(self):
input_types = SaveImageLM.INPUT_TYPES()
optional = input_types["optional"]
assert optional["jpeg_subsampling"][1]["default"] == 0
assert SaveImageLM.save_images.__defaults__[5] == 0
assert SaveImageLM.process_image.__defaults__[7] == 0
widget_spec = cast(Any, optional["jpeg_subsampling"])
assert widget_spec[1]["default"] == 0
save_defaults = cast(tuple[Any, ...], SaveImageLM.save_images.__defaults__ or ())
process_defaults = cast(tuple[Any, ...], SaveImageLM.process_image.__defaults__ or ())
assert save_defaults[5] == 0
assert process_defaults[7] == 0
def test_add_loras_to_prompt_defaults_are_consistent(self):
input_types = SaveImageLM.INPUT_TYPES()
optional = input_types["optional"]
assert optional["add_loras_to_prompt"][1]["default"] is False
assert SaveImageLM.save_images.__defaults__[-1] is False
assert SaveImageLM.process_image.__defaults__[-1] is False
widget_spec = cast(Any, optional["add_loras_to_prompt"])
assert widget_spec[1]["default"] is False
save_defaults = cast(tuple[Any, ...], SaveImageLM.save_images.__defaults__ or ())
process_defaults = cast(tuple[Any, ...], SaveImageLM.process_image.__defaults__ or ())
assert save_defaults[-1] is False
assert process_defaults[-1] is False
def test_png_does_not_pass_webp_method_or_jpeg_subsampling(monkeypatch, tmp_path):

View File

@@ -34,7 +34,7 @@ class _DummyModel:
def test_nunchaku_load_lora_skips_missing_lora(monkeypatch, caplog):
import folder_paths
import folder_paths # pyright: ignore[reportMissingImports]
dummy_model = _DummyModel()