Skip to content

Add return type annotation for Construct.sizeof#1117

Open
laomaiweng wants to merge 1 commit intoconstruct:masterfrom
laomaiweng:patch-1
Open

Add return type annotation for Construct.sizeof#1117
laomaiweng wants to merge 1 commit intoconstruct:masterfrom
laomaiweng:patch-1

Conversation

@laomaiweng
Copy link

The default implementation of Construct.sizeof unconditionally raises a SizeofError, because it is meant to be overridden in subclasses. This confuses some type checkers (e.g., pyright) which incorrectly (from construct's point-of-view) infer Construct.sizeof to not return, assigning it the NoReturn return type.

Explicitly set the return type hint for Construct.sizeof to int, so that pyright correctly deals with this function.

The default implementation of `Construct.sizeof` unconditionally raises a `SizeofError`, because it is meant to be overridden in subclasses. This confuses some type checkers (e.g., pyright) which incorrectly infer `Construct.sizeof` to not return (assigning the `NoReturn` return type).

Explicitly set the return type hint for `Construct.sizeof` to `int`, so that pyright correctly deals with this function.
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