(
self, escape_comprehensions: bool = False, type_param: bool = False
)
| 7457 | return kind |
| 7458 | |
| 7459 | def current_symbol_table( |
| 7460 | self, escape_comprehensions: bool = False, type_param: bool = False |
| 7461 | ) -> SymbolTable: |
| 7462 | if type_param and self.scope_stack[-1] == SCOPE_ANNOTATION: |
| 7463 | n = self.locals[-1] |
| 7464 | assert n is not None |
| 7465 | return n |
| 7466 | elif self.is_func_scope(): |
| 7467 | if self.scope_stack[-1] == SCOPE_ANNOTATION: |
| 7468 | n = self.locals[-2] |
| 7469 | else: |
| 7470 | n = self.locals[-1] |
| 7471 | assert n is not None |
| 7472 | if escape_comprehensions: |
| 7473 | assert len(self.locals) == len(self.scope_stack) |
| 7474 | # Retrieve the symbol table from the enclosing non-comprehension scope. |
| 7475 | for i, scope_type in enumerate(reversed(self.scope_stack)): |
| 7476 | if scope_type != SCOPE_COMPREHENSION: |
| 7477 | if i == len(self.locals) - 1: # The last iteration. |
| 7478 | # The caller of the comprehension is in the global space. |
| 7479 | names = self.globals |
| 7480 | else: |
| 7481 | names_candidate = self.locals[-1 - i] |
| 7482 | assert ( |
| 7483 | names_candidate is not None |
| 7484 | ), "Escaping comprehension from invalid scope" |
| 7485 | names = names_candidate |
| 7486 | break |
| 7487 | else: |
| 7488 | assert False, "Should have at least one non-comprehension scope" |
| 7489 | else: |
| 7490 | names = n |
| 7491 | assert names is not None |
| 7492 | elif self.type is not None: |
| 7493 | names = self.type.names |
| 7494 | else: |
| 7495 | names = self.globals |
| 7496 | return names |
| 7497 | |
| 7498 | def is_global_or_nonlocal(self, name: str) -> bool: |
| 7499 | return self.is_func_scope() and ( |
no test coverage detected