5
5
from inspect import CO_VARARGS
6
6
from inspect import CO_VARKEYWORDS
7
7
from traceback import format_exception_only
8
+ from types import CodeType
8
9
from types import TracebackType
10
+ from typing import Any
11
+ from typing import Dict
9
12
from typing import Generic
13
+ from typing import List
10
14
from typing import Optional
11
15
from typing import Pattern
16
+ from typing import Set
12
17
from typing import Tuple
13
18
from typing import TypeVar
14
19
from typing import Union
29
34
class Code :
30
35
""" wrapper around Python code objects """
31
36
32
- def __init__ (self , rawcode ):
37
+ def __init__ (self , rawcode ) -> None :
33
38
if not hasattr (rawcode , "co_filename" ):
34
39
rawcode = getrawcode (rawcode )
35
40
try :
@@ -38,7 +43,7 @@ def __init__(self, rawcode):
38
43
self .name = rawcode .co_name
39
44
except AttributeError :
40
45
raise TypeError ("not a code object: {!r}" .format (rawcode ))
41
- self .raw = rawcode
46
+ self .raw = rawcode # type: CodeType
42
47
43
48
def __eq__ (self , other ):
44
49
return self .raw == other .raw
@@ -351,7 +356,7 @@ def recursionindex(self):
351
356
""" return the index of the frame/TracebackEntry where recursion
352
357
originates if appropriate, None if no recursion occurred
353
358
"""
354
- cache = {}
359
+ cache = {} # type: Dict[Tuple[Any, int, int], List[Dict[str, Any]]]
355
360
for i , entry in enumerate (self ):
356
361
# id for the code.raw is needed to work around
357
362
# the strange metaprogramming in the decorator lib from pypi
@@ -650,7 +655,7 @@ def repr_args(self, entry):
650
655
args .append ((argname , saferepr (argvalue )))
651
656
return ReprFuncArgs (args )
652
657
653
- def get_source (self , source , line_index = - 1 , excinfo = None , short = False ):
658
+ def get_source (self , source , line_index = - 1 , excinfo = None , short = False ) -> List [ str ] :
654
659
""" return formatted and marked up source lines. """
655
660
import _pytest ._code
656
661
@@ -722,7 +727,7 @@ def repr_traceback_entry(self, entry, excinfo=None):
722
727
else :
723
728
line_index = entry .lineno - entry .getfirstlinesource ()
724
729
725
- lines = []
730
+ lines = [] # type: List[str]
726
731
style = entry ._repr_style
727
732
if style is None :
728
733
style = self .style
@@ -799,7 +804,7 @@ def _truncate_recursive_traceback(self, traceback):
799
804
exc_msg = str (e ),
800
805
max_frames = max_frames ,
801
806
total = len (traceback ),
802
- )
807
+ ) # type: Optional[str]
803
808
traceback = traceback [:max_frames ] + traceback [- max_frames :]
804
809
else :
805
810
if recursionindex is not None :
@@ -812,10 +817,12 @@ def _truncate_recursive_traceback(self, traceback):
812
817
813
818
def repr_excinfo (self , excinfo ):
814
819
815
- repr_chain = []
820
+ repr_chain = (
821
+ []
822
+ ) # type: List[Tuple[ReprTraceback, Optional[ReprFileLocation], Optional[str]]]
816
823
e = excinfo .value
817
824
descr = None
818
- seen = set ()
825
+ seen = set () # type: Set[int]
819
826
while e is not None and id (e ) not in seen :
820
827
seen .add (id (e ))
821
828
if excinfo :
@@ -868,8 +875,8 @@ def __repr__(self):
868
875
869
876
870
877
class ExceptionRepr (TerminalRepr ):
871
- def __init__ (self ):
872
- self .sections = []
878
+ def __init__ (self ) -> None :
879
+ self .sections = [] # type: List[Tuple[str, str, str]]
873
880
874
881
def addsection (self , name , content , sep = "-" ):
875
882
self .sections .append ((name , content , sep ))
0 commit comments