52
52
Optional ,
53
53
Tuple ,
54
54
Type ,
55
- TypeVar ,
56
55
Union ,
57
56
cast ,
58
57
TYPE_CHECKING ,
59
58
)
59
+ from typing import (
60
+ TypeVar ,
61
+ )
60
62
61
63
if TYPE_CHECKING :
62
64
from scapy .asn1packet import ASN1_Packet
@@ -181,7 +183,7 @@ def extract_packet(self,
181
183
try :
182
184
c = cls (s , _underlayer = _underlayer )
183
185
except ASN1F_badsequence :
184
- c = packet .Raw (s , _underlayer = _underlayer )
186
+ c = packet .Raw (s , _underlayer = _underlayer ) # type: ignore
185
187
cpad = c .getlayer (packet .Raw )
186
188
s = b""
187
189
if cpad is not None :
@@ -229,8 +231,8 @@ def __str__(self):
229
231
return repr (self )
230
232
231
233
def randval (self ):
232
- # type: () -> RandField[Any ]
233
- return RandInt ()
234
+ # type: () -> RandField[_I ]
235
+ return cast ( RandField [ _I ], RandInt () )
234
236
235
237
236
238
############################
@@ -527,7 +529,7 @@ def __init__(self,
527
529
):
528
530
# type: (...) -> None
529
531
if isinstance (cls , type ) and issubclass (cls , ASN1F_field ):
530
- self .fld = cast ( Type [ ASN1F_field [ Any , Any ]], cls )
532
+ self .fld = cls
531
533
self ._extract_packet = lambda s , pkt : self .fld (
532
534
self .name , b"" ).m2i (pkt , s )
533
535
self .holds_packets = 0
@@ -696,7 +698,6 @@ def __init__(self, name, default, *args, **kwargs):
696
698
else :
697
699
self .choices [p .ASN1_root .network_tag ] = p
698
700
elif hasattr (p , "ASN1_tag" ):
699
- p = cast (Union [ASN1F_PACKET , Type [ASN1F_field [Any , Any ]]], p )
700
701
if isinstance (p , type ):
701
702
# should be ASN1F_field class
702
703
self .choices [int (p .ASN1_tag )] = p
@@ -735,9 +736,8 @@ def m2i(self, pkt, s):
735
736
)
736
737
)
737
738
if hasattr (choice , "ASN1_root" ):
738
- choice = cast ('ASN1_Packet' , choice )
739
739
# we don't want to import ASN1_Packet in this module...
740
- return self .extract_packet (choice , s , _underlayer = pkt )
740
+ return self .extract_packet (choice , s , _underlayer = pkt ) # type: ignore
741
741
elif isinstance (choice , type ):
742
742
return choice (self .name , b"" ).m2i (pkt , s )
743
743
else :
@@ -767,7 +767,7 @@ def randval(self):
767
767
elif hasattr (p , "ASN1_tag" ):
768
768
if isinstance (p , type ):
769
769
# should be (basic) ASN1F_field class
770
- randchoices .append (p ("dummy" , None ).randval ()) # type: ignore
770
+ randchoices .append (p ("dummy" , None ).randval ())
771
771
else :
772
772
# should be ASN1F_PACKET instance
773
773
randchoices .append (p .randval ())
@@ -841,7 +841,7 @@ def i2m(self,
841
841
implicit_tag = self .implicit_tag ,
842
842
explicit_tag = self .explicit_tag )
843
843
844
- def randval (self ):
844
+ def randval (self ): # type: ignore
845
845
# type: () -> ASN1_Packet
846
846
return packet .fuzz (self .cls ())
847
847
@@ -863,8 +863,10 @@ def __init__(self,
863
863
):
864
864
# type: (...) -> None
865
865
self .cls = cls
866
- super (ASN1F_BIT_STRING_ENCAPS , self ).__init__ (
867
- name , default and raw (default ), context = context ,
866
+ super (ASN1F_BIT_STRING_ENCAPS , self ).__init__ ( # type: ignore
867
+ name ,
868
+ default and raw (default ),
869
+ context = context ,
868
870
implicit_tag = implicit_tag ,
869
871
explicit_tag = explicit_tag
870
872
)
0 commit comments