Skip to content

Typed - #160

Open
markus-becker-tridonic-com wants to merge 1 commit into
sde1000:masterfrom
tridonic-com:typed
Open

Typed#160
markus-becker-tridonic-com wants to merge 1 commit into
sde1000:masterfrom
tridonic-com:typed

Conversation

@markus-becker-tridonic-com

@markus-becker-tridonic-com markus-becker-tridonic-com commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Make python-dali a typed (PEP 561) package so downstream consumers' type
checkers follow it as a typed dependency. Ships py.typed markers for every
public subpackage and annotates the public signatures consumers call.

What's included (top commit)

  • py.typed markers for dali, dali/device, dali/driver, dali/gear,
    dali/memory, included in the built distribution via MANIFEST.in +
    include_package_data.
  • Public-signature annotations: Response/Command (command.py), the
    address constructors, the gear/device command bases, the commissioning and
    query sequences, memory-bank read_all, and the typed exceptions.
  • from __future__ import annotations where PEP 604 unions require it on the
    3.7 floor; fixes the malformed dict[(int, int), int] →
    dict[tuple[int, int], int] annotation.
  • Signatures only — no behavior change.

⚠️ Stacking

This branch is stacked on the full integration feature set (serialx
migration, part 306, DT8 colour sequences, control-device commissioning, DT1).
The typing change is the top commit (574b461c13cb3606e14aa585f9d4bbf27805ede2); against master the PR
shows ~20 commits because the annotations cover symbols introduced across those
branches and cannot stand alone. Review the top commit, or retarget the PR base
to the appropriate branch once the underlying stack has landed.

Testing

  • python-dali suite: 161 passed.
  • Downstream verification: the Home Assistant DALI integration passes strict
    mypy with 0 errors against a non-editable wheel of this branch, and
    py.typed is present in the wheel RECORD.

Ship PEP 561 py.typed markers for every public subpackage (dali, device,
driver, gear, memory) and include them in the built distribution via
MANIFEST.in and include_package_data, so downstream consumers' type
checkers follow python-dali as a typed dependency.

Annotate the public signatures the consumers call: Response/Command in
command.py, the address constructors, the gear/device command bases, the
commissioning and query sequences, memory bank read_all, and the typed
exceptions. Signatures only; no behavior change. Add
`from __future__ import annotations` where PEP 604 unions require it on
the 3.7 floor, and fix the malformed dict[(int, int), int] annotation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sde1000

sde1000 commented Oct 16, 2026

Copy link
Copy Markdown
Owner

I've rebased this again on current master (the "Unify driver send()/run_sequence() and add a transmit priority" commit) so I can read the diff more easily, and run tests.

Notes:

  • All the py.typed files except the one in dali/ are redundant; the existence of the one in the top-level package implies that all sub-package public interfaces are typed too.
  • This commit doesn't enable the whole library to pass type checking, it only annotates (possibly some of) the public interface.
  • It isn't possible to use a type checker at the moment to check that the annotations are correct.

I think I'm going to try to add typing to the whole library, not just the public interface; that way, type checking can be part of the test suite.

@sde1000

sde1000 commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Work in progress on typing for the whole library is in the "typing" branch; currently dali/gear/ and dali/device/ (and implicitly all the python files directly in dali/) are passing mypy --strict and I'm working on dali/memory/

@markus-becker-tridonic-com

Copy link
Copy Markdown
Contributor Author

Work in progress on typing for the whole library is in the "typing" branch; currently dali/gear/ and dali/device/ (and implicitly all the python files directly in dali/) are passing mypy --strict and I'm working on dali/memory/

Any preference on how to handle the dependencies pyusb, pymodbus?

  • [mypy] config section to ignore those?
  • Inline # type: ignore?

@sde1000

sde1000 commented Oct 19, 2026

Copy link
Copy Markdown
Owner

They won't be an issue once drivers are removed from python-dali! Fully typing the drivers can be a separate project.

This branch has not been deployed

No deployments
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