Make the generated Python type-check - #131
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An array register declares
lengthas a plain annotation, and the example converter presents the type the schema promises.Array register length
lengthis declared in the body of the metaclass that owns array registers, so each register class carries its own value. Annotating itClassVarin a generated class body claims instead that the attribute is shared across every register class, which is not what it means.addresskeeps itsClassVar, becauseRegisterBaseis 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
DataConverterin the interop project now usesnp.int32rather than a Pythonint. AninterfaceTypeofintmaps tonp.int32throughout 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.