| 52 | __slots__ = ("__storage",) |
| 53 | |
| 54 | def __init__(self, context_var: ContextVar[dict[str, t.Any]] | None = None) -> None: |
| 55 | if context_var is None: |
| 56 | # A ContextVar not created at global scope interferes with |
| 57 | # Python's garbage collection. However, a local only makes |
| 58 | # sense defined at the global scope as well, in which case |
| 59 | # the GC issue doesn't seem relevant. |
| 60 | context_var = ContextVar(f"werkzeug.Local<{id(self)}>.storage") |
| 61 | |
| 62 | object.__setattr__(self, "_Local__storage", context_var) |
| 63 | |
| 64 | def __iter__(self) -> t.Iterator[tuple[str, t.Any]]: |
| 65 | return iter(self.__storage.get({}).items()) |