Pops the topmost level for assignment tracking and updates the context variables if necessary.
(self, frame)
| 663 | self._assign_stack.append(set()) |
| 664 | |
| 665 | def pop_assign_tracking(self, frame): |
| 666 | """Pops the topmost level for assignment tracking and updates the |
| 667 | context variables if necessary. |
| 668 | """ |
| 669 | vars = self._assign_stack.pop() |
| 670 | if not frame.toplevel or not vars: |
| 671 | return |
| 672 | public_names = [x for x in vars if x[:1] != '_'] |
| 673 | if len(vars) == 1: |
| 674 | name = next(iter(vars)) |
| 675 | ref = frame.symbols.ref(name) |
| 676 | self.writeline('context.vars[%r] = %s' % (name, ref)) |
| 677 | else: |
| 678 | self.writeline('context.vars.update({') |
| 679 | for idx, name in enumerate(vars): |
| 680 | if idx: |
| 681 | self.write(', ') |
| 682 | ref = frame.symbols.ref(name) |
| 683 | self.write('%r: %s' % (name, ref)) |
| 684 | self.write('})') |
| 685 | if public_names: |
| 686 | if len(public_names) == 1: |
| 687 | self.writeline('context.exported_vars.add(%r)' % |
| 688 | public_names[0]) |
| 689 | else: |
| 690 | self.writeline('context.exported_vars.update((%s))' % |
| 691 | ', '.join(imap(repr, public_names))) |
| 692 | |
| 693 | # -- Statement Visitors |
| 694 |