Pops the topmost level for assignment tracking and updates the context variables if necessary.
(self, frame: Frame)
| 782 | self._assign_stack.append(set()) |
| 783 | |
| 784 | def pop_assign_tracking(self, frame: Frame) -> None: |
| 785 | class="st">"""Pops the topmost level for assignment tracking and updates the |
| 786 | context variables if necessary. |
| 787 | class="st">""" |
| 788 | vars = self._assign_stack.pop() |
| 789 | if ( |
| 790 | not frame.block_frame |
| 791 | and not frame.loop_frame |
| 792 | and not frame.toplevel |
| 793 | or not vars |
| 794 | ): |
| 795 | return |
| 796 | public_names = [x for x in vars if x[:1] != class="st">"_"] |
| 797 | if len(vars) == 1: |
| 798 | name = next(iter(vars)) |
| 799 | ref = frame.symbols.ref(name) |
| 800 | if frame.loop_frame: |
| 801 | self.writeline(fclass="st">"_loop_vars[{name!r}] = {ref}") |
| 802 | return |
| 803 | if frame.block_frame: |
| 804 | self.writeline(fclass="st">"_block_vars[{name!r}] = {ref}") |
| 805 | return |
| 806 | self.writeline(fclass="st">"context.vars[{name!r}] = {ref}") |
| 807 | else: |
| 808 | if frame.loop_frame: |
| 809 | self.writeline(class="st">"_loop_vars.update({") |
| 810 | elif frame.block_frame: |
| 811 | self.writeline(class="st">"_block_vars.update({") |
| 812 | else: |
| 813 | self.writeline(class="st">"context.vars.update({") |
| 814 | for idx, name in enumerate(sorted(vars)): |
| 815 | if idx: |
| 816 | self.write(class="st">", ") |
| 817 | ref = frame.symbols.ref(name) |
| 818 | self.write(fclass="st">"{name!r}: {ref}") |
| 819 | self.write(class="st">"})") |
| 820 | if not frame.block_frame and not frame.loop_frame and public_names: |
| 821 | if len(public_names) == 1: |
| 822 | self.writeline(fclass="st">"context.exported_vars.add({public_names[0]!r})") |
| 823 | else: |
| 824 | names_str = class="st">", ".join(map(repr, sorted(public_names))) |
| 825 | self.writeline(fclass="st">"context.exported_vars.update(({names_str}))") |
| 826 | |
| 827 | class="cm"># -- Statement Visitors |
| 828 |
no test coverage detected