Skip to content

Make the generated Python type-check - #131

Merged
glopesdev merged 2 commits into
harp-tech:mainfrom
glopesdev:generated-python-typing
Aug 26, 2026
Merged

Make the generated Python type-check#131
glopesdev merged 2 commits into
harp-tech:mainfrom
glopesdev:generated-python-typing

Conversation

@glopesdev

@glopesdev glopesdev commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

An array register declares length as a plain annotation, and the example converter presents the type the schema promises.

Array register length

length is declared in the body of the metaclass that owns array registers, so each register class carries its own value. Annotating it ClassVar in a generated class body claims instead that the attribute is shared across every register class, which is not what it means.

address keeps its ClassVar, because RegisterBase is an ordinary class and declares it that way. Both annotations end up describing an attribute on the register class, and they differ only because one arrives through the class and the other through its metaclass.

Example converter

DataConverter in the interop project now uses np.int32 rather than a Python int. An interfaceType of int maps to np.int32 throughout the Python target, which is also the annotation the generator emits beside the field, so the hand-written converter was the side that disagreed.

Type-checking in CI

pyright runs over the generated device package after the interop test, against the package that test already assembles, so it is always the module the generator has just produced and there is nothing to keep in step by hand.

pyright is declared in the interop project rather than installed for the step alone, so a local run matches CI. Its floor matches the one harp-tech/python declares for its own checks.

An array register now declares length as a plain annotation rather than
a ClassVar, matching how its metaclass declares it.

The example converter now presents np.int32 rather than a Python int,
the type the schema promises for an interfaceType of int. pyright
reports no errors over the generated package.
@glopesdev
glopesdev requested a review from bruno-f-cruz August 26, 2026 08:17
@glopesdev glopesdev added the feature New planned feature label Aug 26, 2026
CI now runs pyright over the generated device package after the interop
test, using the package that test already assembles.

pyright is declared in the interop project rather than installed for
the step alone, so a local run matches CI.

@bruno-f-cruz bruno-f-cruz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@glopesdev
glopesdev merged commit 7c7c99e into harp-tech:main Aug 26, 2026
9 checks passed
@glopesdev
glopesdev deleted the generated-python-typing branch August 26, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New planned feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants