2525#
2626
2727from abc import ABCMeta
28- from typing import Any , Optional
28+ from typing import cast , Any , BinaryIO , Optional , Type , Union
2929from .base import STRUCTS
3030import hashlib
3131from .c_parser import (parse_struct , parse_def , Tokens )
@@ -82,7 +82,7 @@ def __init__(self, buffer=None, **kargs) -> None:
8282 setattr (self , key , value )
8383
8484 @classmethod
85- def parse (cls , __struct__ , __name__ = None , ** kargs ):
85+ def parse (cls , __struct__ , __name__ : Optional [ str ] = None , ** kargs ) -> Type [ Any ] :
8686 """
8787 Return a new class mapping a C struct/union definition.
8888
@@ -104,7 +104,7 @@ def parse(cls, __struct__, __name__=None, **kargs):
104104 kargs ['__name__' ] = __name__
105105 return type (__name__ , (cls ,), kargs )
106106
107- def unpack (self , buffer ) :
107+ def unpack (self , buffer : Optional [ Union [ bytes , BinaryIO ]]) -> bool :
108108 """
109109 Unpack bytes containing packed C structure data
110110
@@ -116,27 +116,27 @@ def unpack(self, buffer):
116116 return False
117117 return self .unpack_from (buffer )
118118
119- def unpack_from (self , buffer : Optional [bytes ], offset : int = 0 ): # pragma: no cover
119+ def unpack_from (self , buffer : Optional [bytes ], offset : int = 0 ) -> bool : # pragma: no cover
120120 """
121121 Unpack bytes containing packed C structure data
122122
123123 :param buffer: bytes to be unpacked
124124 :param offset: optional buffer offset
125125 """
126- return NotImplemented
126+ raise NotImplementedError
127127
128- def pack (self ): # pragma: no cover
128+ def pack (self ) -> bytes : # pragma: no cover
129129 """
130130 Pack the structure data into bytes
131131 """
132- return NotImplemented
132+ raise NotImplementedError
133133
134134 def clear (self ) -> None :
135135 self .unpack (None )
136136
137137 def __len__ (self ) -> int :
138138 """ Structure size (in bytes) """
139- return self .__size__
139+ return cast ( int , self .__size__ )
140140
141141 @property
142142 def size (self ) -> int :
0 commit comments