Skip to content

fix(style): resolve ty type-checker issues in check-netbox scripts#583

Open
d3flex wants to merge 1 commit into
os-autoinst:masterfrom
d3flex:style/python_checks_ty
Open

fix(style): resolve ty type-checker issues in check-netbox scripts#583
d3flex wants to merge 1 commit into
os-autoinst:masterfrom
d3flex:style/python_checks_ty

Conversation

@d3flex
Copy link
Copy Markdown
Contributor

@d3flex d3flex commented May 13, 2026

  • Use sh.Command("ping") instead of from sh import ping (sh uses getattr magic that ty cannot resolve statically)
  • Move pynetbox model imports behind TYPE_CHECKING in machine-state.py; possible because from __future__ import annotations makes all annotations lazy — unused-machine-power.py lacks that import so dcim must remain a runtime import there
  • Fix loglevel_to_int: / returns float so ty rejects it as int; switch to // and use logging.ERROR as getattr fallback to avoid None
  • Suppress unresolved-import for netsnmp in pyproject.toml; netsnmp is a C extension with no type stubs or py.typed marker

Issue: https://progress.opensuse.org/issues/191575

- Use `sh.Command("ping")` instead of `from sh import ping` (sh uses
  __getattr__ magic that ty cannot resolve statically)
- Move pynetbox model imports behind TYPE_CHECKING in machine-state.py;
  possible because `from __future__ import annotations` makes all
  annotations lazy — unused-machine-power.py lacks that import so dcim
  must remain a runtime import there
- Fix `loglevel_to_int`: `/` returns float so ty rejects it as int;
  switch to `//` and use `logging.ERROR` as getattr fallback to avoid None
- Suppress unresolved-import for netsnmp in pyproject.toml; netsnmp is
  a C extension with no type stubs or py.typed marker

Issue: https://progress.opensuse.org/issues/191575
Signed-off-by: Ioannis Bonatakis <[email protected]>
@d3flex d3flex force-pushed the style/python_checks_ty branch from 6155a4d to dd9d352 Compare May 13, 2026 12:30
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.

1 participant