@@ -271,7 +271,7 @@ def label(self) -> int:
271
271
return self .owner .labels [self .owner .label_indices [self .index ]]
272
272
273
273
@property
274
- def parent (self ):
274
+ def parent (self ) -> Optional [ int ] :
275
275
"""The index of the example that this one is nested directly within."""
276
276
if self .index == 0 :
277
277
return None
@@ -298,13 +298,13 @@ def ir_end(self) -> int:
298
298
return self .owner .ir_ends [self .index ]
299
299
300
300
@property
301
- def depth (self ):
301
+ def depth (self ) -> int :
302
302
"""Depth of this example in the example tree. The top-level example has a
303
303
depth of 0."""
304
304
return self .owner .depths [self .index ]
305
305
306
306
@property
307
- def trivial (self ):
307
+ def trivial (self ) -> bool :
308
308
"""An example is "trivial" if it only contains forced bytes and zero bytes.
309
309
All examples start out as trivial, and then get marked non-trivial when
310
310
we see a byte that is neither forced nor zero."""
@@ -352,6 +352,7 @@ def __init__(self, examples: "Examples"):
352
352
self .example_count = 0
353
353
self .block_count = 0
354
354
self .ir_node_count = 0
355
+ self .result : Any = None
355
356
356
357
def run (self ) -> Any :
357
358
"""Rerun the test case with this visitor and return the
@@ -425,7 +426,7 @@ def calculated_example_property(cls: Type[ExampleProperty]) -> Any:
425
426
name = cls .__name__
426
427
cache_name = "__" + name
427
428
428
- def lazy_calculate (self : "Examples" ) -> IntList :
429
+ def lazy_calculate (self : "Examples" ) -> Any :
429
430
result = getattr (self , cache_name , None )
430
431
if result is None :
431
432
result = cls (self ).run ()
@@ -465,7 +466,14 @@ def __init__(self) -> None:
465
466
def freeze (self ) -> None :
466
467
self .__index_of_labels = None
467
468
468
- def record_ir_draw (self , ir_type , value , * , kwargs , was_forced ):
469
+ def record_ir_draw (
470
+ self ,
471
+ ir_type : IRTypeName ,
472
+ value : IRType ,
473
+ * ,
474
+ kwargs : IRKWargsType ,
475
+ was_forced : bool ,
476
+ ) -> None :
469
477
self .trail .append (IR_NODE_RECORD )
470
478
node = IRNode (
471
479
ir_type = ir_type ,
@@ -517,7 +525,7 @@ def __init__(self, record: ExampleRecord, blocks: "Blocks") -> None:
517
525
self .__children : "Optional[List[Sequence[int]]]" = None
518
526
519
527
class _starts_and_ends (ExampleProperty ):
520
- def begin (self ):
528
+ def begin (self ) -> None :
521
529
self .starts = IntList .of_length (len (self .examples ))
522
530
self .ends = IntList .of_length (len (self .examples ))
523
531
@@ -543,7 +551,7 @@ def ends(self) -> IntList:
543
551
return self .starts_and_ends [1 ]
544
552
545
553
class _ir_starts_and_ends (ExampleProperty ):
546
- def begin (self ):
554
+ def begin (self ) -> None :
547
555
self .starts = IntList .of_length (len (self .examples ))
548
556
self .ends = IntList .of_length (len (self .examples ))
549
557
@@ -570,7 +578,7 @@ def ir_ends(self) -> IntList:
570
578
571
579
class _discarded (ExampleProperty ):
572
580
def begin (self ) -> None :
573
- self .result : "Set[int]" = set () # type: ignore # IntList in parent class
581
+ self .result : "Set[int]" = set ()
574
582
575
583
def finish (self ) -> FrozenSet [int ]:
576
584
return frozenset (self .result )
@@ -584,7 +592,7 @@ def stop_example(self, i: int, *, discarded: bool) -> None:
584
592
class _trivial (ExampleProperty ):
585
593
def begin (self ) -> None :
586
594
self .nontrivial = IntList .of_length (len (self .examples ))
587
- self .result : "Set[int]" = set () # type: ignore # IntList in parent class
595
+ self .result : "Set[int]" = set ()
588
596
589
597
def block (self , i : int ) -> None :
590
598
if not self .examples .blocks .trivial (i ):
@@ -610,7 +618,7 @@ def stop_example(self, i: int, *, discarded: bool) -> None:
610
618
parentage : IntList = calculated_example_property (_parentage )
611
619
612
620
class _depths (ExampleProperty ):
613
- def begin (self ):
621
+ def begin (self ) -> None :
614
622
self .result = IntList .of_length (len (self .examples ))
615
623
616
624
def start_example (self , i : int , label_index : int ) -> None :
@@ -619,10 +627,10 @@ def start_example(self, i: int, label_index: int) -> None:
619
627
depths : IntList = calculated_example_property (_depths )
620
628
621
629
class _ir_tree_nodes (ExampleProperty ):
622
- def begin (self ):
630
+ def begin (self ) -> None :
623
631
self .result = []
624
632
625
- def ir_node (self , ir_node ) :
633
+ def ir_node (self , ir_node : "IRNode" ) -> None :
626
634
self .result .append (ir_node )
627
635
628
636
ir_tree_nodes : "List[IRNode]" = calculated_example_property (_ir_tree_nodes )
@@ -788,7 +796,7 @@ def all_bounds(self) -> Iterable[Tuple[int, int]]:
788
796
prev = e
789
797
790
798
@property
791
- def last_block_length (self ):
799
+ def last_block_length (self ) -> int :
792
800
return self .end (- 1 ) - self .start (- 1 )
793
801
794
802
def __len__ (self ) -> int :
@@ -869,7 +877,7 @@ def __getitem__(self, i: int) -> Block:
869
877
870
878
return result
871
879
872
- def __check_completion (self ):
880
+ def __check_completion (self ) -> None :
873
881
"""The list of blocks is complete if we have created every ``Block``
874
882
object that we currently good and know that no more will be created.
875
883
@@ -899,7 +907,7 @@ def __repr__(self) -> str:
899
907
class _Overrun :
900
908
status = Status .OVERRUN
901
909
902
- def __repr__ (self ):
910
+ def __repr__ (self ) -> str :
903
911
return "Overrun"
904
912
905
913
@@ -1052,7 +1060,7 @@ def __eq__(self, other):
1052
1060
and self .was_forced == other .was_forced
1053
1061
)
1054
1062
1055
- def __hash__ (self ):
1063
+ def __hash__ (self ) -> int :
1056
1064
return hash (
1057
1065
(
1058
1066
self .ir_type ,
@@ -1062,7 +1070,7 @@ def __hash__(self):
1062
1070
)
1063
1071
)
1064
1072
1065
- def __repr__ (self ):
1073
+ def __repr__ (self ) -> str :
1066
1074
# repr to avoid "BytesWarning: str() on a bytes instance" for bytes nodes
1067
1075
forced_marker = " [forced]" if self .was_forced else ""
1068
1076
return f"{ self .ir_type } { self .value !r} { forced_marker } { self .kwargs !r} "
@@ -1911,8 +1919,7 @@ def _compute_draw_float_init_logic(
1911
1919
"writeup - and good luck!"
1912
1920
)
1913
1921
1914
- def permitted (f ):
1915
- assert isinstance (f , float )
1922
+ def permitted (f : float ) -> bool :
1916
1923
if math .isnan (f ):
1917
1924
return allow_nan
1918
1925
if 0 < abs (f ) < smallest_nonzero_magnitude :
@@ -2080,7 +2087,7 @@ def __init__(
2080
2087
self ._node_index = 0
2081
2088
self .start_example (TOP_LABEL )
2082
2089
2083
- def __repr__ (self ):
2090
+ def __repr__ (self ) -> str :
2084
2091
return "ConjectureData(%s, %d bytes%s)" % (
2085
2092
self .status .name ,
2086
2093
len (self .buffer ),
0 commit comments