forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
29 lines (21 loc) · 853 Bytes
/
state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import annotations
from contextlib import contextmanager
from typing import Iterator
from typing_extensions import Final
# These are global mutable state. Don't add anything here unless there's a very
# good reason.
class StrictOptionalState:
# Wrap this in a class since it's faster that using a module-level attribute.
def __init__(self, strict_optional: bool) -> None:
# Value varies by file being processed
self.strict_optional = strict_optional
@contextmanager
def strict_optional_set(self, value: bool) -> Iterator[None]:
saved = self.strict_optional
self.strict_optional = value
try:
yield
finally:
self.strict_optional = saved
state: Final = StrictOptionalState(strict_optional=False)
find_occurrences: tuple[str, str] | None = None