@@ -17,6 +17,7 @@ from construct.lib import (
1717 ListType ,
1818 RebufferedBytesIO ,
1919)
20+ from typing_extensions import Buffer
2021
2122# unfortunately, there are a few duplications with "typing", e.g. Union and Optional, which is why the t. prefix must be used everywhere
2223
@@ -25,6 +26,7 @@ from construct.lib import (
2526# - Higher Kinded Types: https://github.com/python/typing/issues/548
2627# - Higher Kinded Types: https://sobolevn.me/2020/10/higher-kinded-types-in-python
2728
29+ ReadableBuffer : t .TypeAlias = Buffer
2830StreamType = t .IO [bytes ]
2931FilenameType = t .Union [str , bytes , os .PathLike [str ], os .PathLike [bytes ]]
3032PathType = str
@@ -95,7 +97,7 @@ class Construct(t.Generic[ParsedType, BuildTypes]):
9597 docs : str
9698 flagbuildnone : bool
9799 parsed : t .Optional [t .Callable [[ParsedType , Context ], None ]]
98- def parse (self , data : bytes , ** contextkw : ContextKWType ) -> ParsedType : ...
100+ def parse (self , data : ReadableBuffer , ** contextkw : ContextKWType ) -> ParsedType : ...
99101 def parse_stream (
100102 self , stream : StreamType , ** contextkw : ContextKWType
101103 ) -> ParsedType : ...
@@ -113,7 +115,9 @@ class Construct(t.Generic[ParsedType, BuildTypes]):
113115 def compile (
114116 self , filename : FilenameType = ...
115117 ) -> Construct [ParsedType , BuildTypes ]: ...
116- def benchmark (self , sampledata : bytes , filename : FilenameType = ...) -> str : ...
118+ def benchmark (
119+ self , sampledata : ReadableBuffer , filename : FilenameType = ...
120+ ) -> str : ...
117121 def export_ksy (
118122 self , schemaname : str = ..., filename : FilenameType = ...
119123 ) -> str : ...
0 commit comments