fixing pyright issues

This commit is contained in:
Tim Rid 2021-05-23 16:22:40 +02:00
parent 22a0ed7f24
commit 2b5967e11d
7 changed files with 36 additions and 22 deletions

View file

@ -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: ...

View file

@ -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]): ...

View file

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# pyright: strict
import dataclasses
import textwrap
import typing as t

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python
from setuptools import setup
version_string = "?.?.?"
exec(open("./construct_typed/version.py").read())
setup(

View file

@ -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: ...

View file

@ -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)

View file

@ -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: