Skip to content

typing and typechecks updates#4722

Merged
vladmandic merged 14 commits intovladmandic:devfrom
awsr:various1
Apr 2, 2026
Merged

typing and typechecks updates#4722
vladmandic merged 14 commits intovladmandic:devfrom
awsr:various1

Conversation

@awsr
Copy link
Copy Markdown
Contributor

@awsr awsr commented Mar 29, 2026

A partial set of various updates that I'm sending through because another upcoming update would probably be better off as its own PR but it builds off of a few of these updates.

  • Update API models to match actual code behavior:
    • ResScripts
    • ResEmbeddings
  • Type enforcement for ResGPU (lists don't support sized typing, only tuples do).
  • Upgrade namedtuple to typed NamedTuple.
    • ScriptFile
    • ScriptClassData
    • Grid
  • Re-add fixes to sd_unet.py and sd_model.py (separate from the PEP 484 update this time).
  • More typing annotations.
  • Aside from the previous two additions, the only real logic changes that could affect behavior are:
    • GPU API chart data using tuples instead of lists for enforcing the two-value return.
    • Nudenet:
      • Checking if p is actually None instead of relying on a copy parameter that's never used (and its only use was to get the same behavior, but not in a way that was type-safe or made sense).
      • Checking for actual Class type instead of blindly inferring based on the existence of an attribute.
      • Relaxing call requirements on functions that could be passed a value, but didn't actually use it.
    • Refactoring get_grid_size to work better with static type checkers.
      • Slightly safer in data handling, and now properly has the inferred tuple[int, int] return type.

Side note: I have no idea why, but for some reason the script would be listed as invalid and the name listed as "unknown" when using the direct import format from modules.scripts_postprocessing import PostprocessedImage, ScriptPostprocessing instead of from modules import scripts_postprocessing and accessing them as attributes.

@vladmandic
Copy link
Copy Markdown
Owner

changes look sane to me. not a huge fan of walrus usage in grid size - nothing wrong with it, but it makes it difficult to read/understand upon first look.
also, change from collections.nametupple to NamedTuple class feels ok, but would need testing.
if you're ok with it, i'd merge this after this release simply to minimize impact this late?

@vladmandic vladmandic changed the title Various update 1 typing and typechecks updates Mar 30, 2026
@awsr
Copy link
Copy Markdown
Contributor Author

awsr commented Mar 31, 2026

Sounds good to me

@vladmandic vladmandic merged commit 668a941 into vladmandic:dev Apr 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants