| 360 | |
| 361 | |
| 362 | class _FastLocalStack(threading.local): |
| 363 | |
| 364 | def __init__(self): |
| 365 | self.stack = [] |
| 366 | self.push = self.stack.append |
| 367 | self.pop = self.stack.pop |
| 368 | super().__init__() |
| 369 | |
| 370 | @property |
| 371 | def top(self): |
| 372 | try: |
| 373 | return self.stack[-1] |
| 374 | except (AttributeError, IndexError): |
| 375 | return None |
| 376 | |
| 377 | __class_getitem__ = classmethod(types.GenericAlias) |
| 378 | |
| 379 | def __len__(self): |
| 380 | return len(self.stack) |
| 381 | |
| 382 | |
| 383 | if USE_FAST_LOCALS: # pragma: no cover |