MCPcopy Index your code
hub / github.com/python/mypy / FrameContext

Class FrameContext

mypy/binder.py:88–140  ·  view source on GitHub ↗

Context manager pushing a Frame to ConditionalTypeBinder. See frame_context() below for documentation on parameters. We use this class instead of @contextmanager as a mypyc-specific performance optimization.

Source from the content-addressed store, hash-verified

86
87
88class FrameContext:
89 """Context manager pushing a Frame to ConditionalTypeBinder.
90
91 See frame_context() below for documentation on parameters. We use this class
92 instead of @contextmanager as a mypyc-specific performance optimization.
93 """
94
95 def __init__(
96 self,
97 binder: ConditionalTypeBinder,
98 can_skip: bool,
99 fall_through: int,
100 break_frame: int,
101 continue_frame: int,
102 conditional_frame: bool,
103 try_frame: bool,
104 discard: bool,
105 ) -> None:
106 self.binder = binder
107 self.can_skip = can_skip
108 self.fall_through = fall_through
109 self.break_frame = break_frame
110 self.continue_frame = continue_frame
111 self.conditional_frame = conditional_frame
112 self.try_frame = try_frame
113 self.discard = discard
114
115 def __enter__(self) -> Frame:
116 assert len(self.binder.frames) > 1
117
118 if self.break_frame:
119 self.binder.break_frames.append(len(self.binder.frames) - self.break_frame)
120 if self.continue_frame:
121 self.binder.continue_frames.append(len(self.binder.frames) - self.continue_frame)
122 if self.try_frame:
123 self.binder.try_frames.add(len(self.binder.frames) - 1)
124
125 new_frame = self.binder.push_frame(self.conditional_frame)
126 if self.try_frame:
127 # An exception may occur immediately
128 self.binder.allow_jump(-1)
129 return new_frame
130
131 def __exit__(self, exc_type: object, exc_val: object, exc_tb: object) -> Literal[False]:
132 self.binder.pop_frame(self.can_skip, self.fall_through, discard=self.discard)
133
134 if self.break_frame:
135 self.binder.break_frames.pop()
136 if self.continue_frame:
137 self.binder.continue_frames.pop()
138 if self.try_frame:
139 self.binder.try_frames.remove(len(self.binder.frames) - 1)
140 return False
141
142
143class ConditionalTypeBinder:

Callers 1

frame_contextMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…