Use TYPE_CHECKING instead of magic MYPY variable. (#8770)

This commit is contained in:
Patrick Cloke 2020-11-17 09:09:40 -05:00 committed by GitHub
parent f737368a26
commit 473dfec1e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 9 deletions

1
changelog.d/8770.misc Normal file
View File

@ -0,0 +1 @@
Use `TYPE_CHECKING` instead of magic `MYPY` variable.

View File

@ -15,13 +15,12 @@
# limitations under the License. # limitations under the License.
import inspect import inspect
from typing import Any, Dict, List, Optional, Tuple from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
from synapse.spam_checker_api import RegistrationBehaviour from synapse.spam_checker_api import RegistrationBehaviour
from synapse.types import Collection from synapse.types import Collection
MYPY = False if TYPE_CHECKING:
if MYPY:
import synapse.events import synapse.events
import synapse.server import synapse.server

View File

@ -25,7 +25,7 @@ The methods that define policy are:
import abc import abc
import logging import logging
from contextlib import contextmanager from contextlib import contextmanager
from typing import Dict, Iterable, List, Set, Tuple from typing import TYPE_CHECKING, Dict, Iterable, List, Set, Tuple
from prometheus_client import Counter from prometheus_client import Counter
from typing_extensions import ContextManager from typing_extensions import ContextManager
@ -46,8 +46,7 @@ from synapse.util.caches.descriptors import cached
from synapse.util.metrics import Measure from synapse.util.metrics import Measure
from synapse.util.wheel_timer import WheelTimer from synapse.util.wheel_timer import WheelTimer
MYPY = False if TYPE_CHECKING:
if MYPY:
from synapse.server import HomeServer from synapse.server import HomeServer
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View File

@ -18,7 +18,7 @@
import logging import logging
import re import re
from typing import List, Optional from typing import TYPE_CHECKING, List, Optional
from urllib import parse as urlparse from urllib import parse as urlparse
from synapse.api.constants import EventTypes, Membership from synapse.api.constants import EventTypes, Membership
@ -48,8 +48,7 @@ from synapse.types import RoomAlias, RoomID, StreamToken, ThirdPartyInstanceID,
from synapse.util import json_decoder from synapse.util import json_decoder
from synapse.util.stringutils import random_string from synapse.util.stringutils import random_string
MYPY = False if TYPE_CHECKING:
if MYPY:
import synapse.server import synapse.server
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)