diff --git a/construct-stubs/core.pyi b/construct-stubs/core.pyi index 879c0cc..e5cda23 100644 --- a/construct-stubs/core.pyi +++ b/construct-stubs/core.pyi @@ -177,7 +177,7 @@ class Adapter( cls, subcon: Construct[SubconParsedType, SubconBuildTypes] ) -> Adapter[SubconParsedType, SubconBuildTypes, ParsedType, BuildTypes]: ... def _decode( - self, obj: SubconParsedType, context: Context, path: PathType + self, obj: SubconBuildTypes, context: Context, path: PathType ) -> ParsedType: ... def _encode( self, obj: BuildTypes, context: Context, path: PathType @@ -193,7 +193,7 @@ class Validator( ] ): def _validate( - self, obj: SubconParsedType, context: Context, path: PathType + self, obj: SubconBuildTypes, context: Context, path: PathType ) -> bool: ... class Tunnel( @@ -356,7 +356,7 @@ def PaddedString( length: ConstantOrContextLambda[int], encoding: StringEncoded.ENCODING ) -> StringEncoded[str, str]: ... def PascalString( - lengthfield: Construct[ParsedType, BuildTypes], encoding: StringEncoded.ENCODING + lengthfield: Construct[int, int], encoding: StringEncoded.ENCODING ) -> StringEncoded[str, str]: ... def CString(encoding: StringEncoded.ENCODING) -> StringEncoded[str, str]: ... def GreedyString(encoding: StringEncoded.ENCODING) -> StringEncoded[str, str]: ... @@ -824,9 +824,16 @@ class Pointer( stream: t.Optional[t.Callable[[Context], StreamType]] = ..., ) -> None: ... -class Peek( - Subconstruct[SubconParsedType, SubconBuildTypes, SubconParsedType, t.Any] -): ... +class Peek(Subconstruct[SubconParsedType, SubconBuildTypes, ParsedType, BuildTypes]): + def __new__( + cls, + subcon: Construct[SubconParsedType, SubconBuildTypes], + ) -> Peek[ + SubconParsedType, + SubconBuildTypes, + SubconParsedType, + t.Union[SubconBuildTypes, None], + ]: ... class Seek(Construct[int, None]): at: ConstantOrContextLambda[int] @@ -1044,14 +1051,16 @@ class Rebuffered( # =============================================================================== # lazy equivalents # =============================================================================== -class Lazy( - Subconstruct[ +class Lazy(Subconstruct[SubconParsedType, SubconBuildTypes, ParsedType, BuildTypes]): + def __new__( + cls, + subcon: Construct[SubconParsedType, SubconBuildTypes], + ) -> Lazy[ SubconParsedType, SubconBuildTypes, t.Callable[[], SubconParsedType], t.Union[t.Callable[[], SubconParsedType], SubconParsedType], - ] -): ... + ]: ... class LazyContainer(t.Generic[ContainerType], t.Dict[str, ContainerType]): def __getattr__(self, name: str) -> ContainerType: ... diff --git a/construct-stubs/debug.pyi b/construct-stubs/debug.pyi index 3b44b04..1234663 100644 --- a/construct-stubs/debug.pyi +++ b/construct-stubs/debug.pyi @@ -9,4 +9,4 @@ class Probe(Construct[None, None]): self, into: t.Optional[ContextLambda] = ..., lookahead: int = ... ) -> None: ... -class Debugger(Subconstruct[None, None]): ... +class Debugger(Subconstruct[None, None, None, None]): ... diff --git a/construct_typed/dataclass_struct.py b/construct_typed/dataclass_struct.py index 444ce21..78d2e59 100644 --- a/construct_typed/dataclass_struct.py +++ b/construct_typed/dataclass_struct.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# pyright: strict import dataclasses import textwrap import typing as t diff --git a/setup.py b/setup.py index c5d0975..602dda0 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from setuptools import setup +version_string = "?.?.?" exec(open("./construct_typed/version.py").read()) setup( diff --git a/tests/declarativeunittest.pyi b/tests/declarativeunittest.pyi index 985cd0a..e2f8cab 100644 --- a/tests/declarativeunittest.pyi +++ b/tests/declarativeunittest.pyi @@ -92,18 +92,18 @@ def common( ) -> None: ... @t.overload def common( - format: Construct[ParsedType, BuildTypes], + format: Construct[ParsedType, t.Any], datasample: Buffer, objsample: ParsedType, sizesample: t.Union[int, t.Type[Exception]] = ..., **kw: t.Any ) -> None: ... def setattrs(obj: T, **kwargs: t.Any) -> T: ... -def commonhex(format: Construct[ParsedType, BuildTypes], hexdata: str) -> None: ... +def commonhex(format: Construct[t.Any, t.Any], hexdata: str) -> None: ... def commondumpdeprecated( - format: Construct[ParsedType, BuildTypes], filename: str + format: Construct[t.Any, t.Any], filename: str ) -> None: ... -def commondump(format: Construct[ParsedType, BuildTypes], filename: str) -> None: ... +def commondump(format: Construct[t.Any, t.Any], filename: str) -> None: ... def commonbytes( - format: Construct[ParsedType, BuildTypes], data: ParsedType + format: Construct[ParsedType, t.Any], data: ParsedType ) -> None: ... diff --git a/tests/test_core.py b/tests/test_core.py index b9ecd0c..96b9b91 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -622,7 +622,7 @@ def test_focusedseq() -> None: def test_pickled() -> None: import pickle - obj = [(), 1, 2.3, {}, [], bytes(1), ""] + obj: t.List[t.Any] = [(), 1, 2.3, {}, [], bytes(1), ""] data = pickle.dumps(obj) common(Pickled, data, obj) diff --git a/tests/test_typed.py b/tests/test_typed.py index 4f948c2..d74e025 100644 --- a/tests/test_typed.py +++ b/tests/test_typed.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- - +# pyright: strict import dataclasses import enum +import typing as t import construct as cs -from construct_typed import csfield, DataclassMixin, DataclassStruct, DataclassBitStruct import construct_typed as cst -import typing as t +from construct_typed import DataclassBitStruct, DataclassMixin, DataclassStruct, csfield from .declarativeunittest import common, raises, setattrs @@ -282,7 +282,8 @@ def test_dataclass_struct_no_DataclassMixin() -> None: a: int = csfield(cs.Int16ub) b: int = csfield(cs.Int8ub) - assert raises(lambda: DataclassStruct(TestContainer)) == TypeError + cls = t.cast(t.Type[DataclassMixin], TestContainer) + assert raises(lambda: DataclassStruct(cls)) == TypeError def test_dataclass_struct_wrong_container() -> None: @@ -379,7 +380,8 @@ def test_tenum_no_enumbase() -> None: a = 1 b = 2 - assert raises(lambda: cst.TEnum(cs.Byte, E)) == TypeError + cls = t.cast(t.Type[cst.EnumBase], E) + assert raises(lambda: cst.TEnum(cs.Byte, cls)) == TypeError def test_dataclass_struct_wrong_enumbase() -> None: