Commit 5282a98
committed
[mypyc] Don't load forward ref targets while setting up non-ext __annotations__
Take this example:
from typing import NamedTuple
class VTableMethod(NamedTuple):
cls: "ClassIR"
class ClassIR: pass
In irbuild::classdef::add_non_ext_class_attr_ann(), mypyc tries to
assign the ClassIR type object to VTableMethod's __annotations__. This
causes a segfault as ClassIR won't be initialized and allocated until
*after* the NamedTuple is set up.
Fortunately, AssignmentStmt preserves the unanalyzed type (UnboundType).
If `stmt.unanalyzed_type.orginal_str_expr` is not None, then we know
we're dealing with a forward ref and should just load the string
instead.
Unfortunately, it seems difficult (or impossible?) to infer whether
an annotation is a forward reference when the annotations future is
enabled and the annotation isn't a string.1 parent 2413578 commit 5282a98
2 files changed
+15
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
556 | 556 | | |
557 | 557 | | |
558 | 558 | | |
| 559 | + | |
559 | 560 | | |
560 | 561 | | |
561 | 562 | | |
| |||
565 | 566 | | |
566 | 567 | | |
567 | 568 | | |
568 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
569 | 577 | | |
570 | 578 | | |
571 | 579 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | 102 | | |
105 | 103 | | |
106 | 104 | | |
| |||
119 | 117 | | |
120 | 118 | | |
121 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
122 | 124 | | |
123 | | - | |
| 125 | + | |
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
132 | | - | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
0 commit comments