From 0068b015f452f0a5ece4e2fa75539c81aaaaeb2a Mon Sep 17 00:00:00 2001 From: Quentin Minster Picavet Date: Tue, 29 Jul 2025 00:22:07 +0200 Subject: [PATCH] Add return type annotation for Construct.sizeof 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. --- construct/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/construct/core.py b/construct/core.py index 3d0e7539..e63c617a 100644 --- a/construct/core.py +++ b/construct/core.py @@ -478,7 +478,7 @@ def _build(self, obj, stream, context, path): """Override in your subclass.""" raise NotImplementedError - def sizeof(self, **contextkw): + def sizeof(self, **contextkw) -> int: r""" Calculate the size of this object, optionally using a context.