typing: consolidate "if not globals():" trick
Removes redundant inline comments. I think pycompat is good place to host
this kind of constants.
--- a/mercurial/branchmap.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/branchmap.py Tue Nov 19 23:49:05 2019 +0900
@@ -27,7 +27,7 @@
stringutil,
)
-if not globals():
+if pycompat.TYPE_CHECKING:
from typing import (
Any,
Callable,
--- a/mercurial/cmdutil.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/cmdutil.py Tue Nov 19 23:49:05 2019 +0900
@@ -61,7 +61,7 @@
stringutil,
)
-if not globals():
+if pycompat.TYPE_CHECKING:
from typing import (
Any,
Dict,
--- a/mercurial/encoding.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/encoding.py Tue Nov 19 23:49:05 2019 +0900
@@ -20,14 +20,11 @@
from .pure import charencode as charencodepure
-_TYPE_CHECKING = False
-
-if not globals(): # hide this from non-pytype users
+if pycompat.TYPE_CHECKING:
from typing import (
Any,
Callable,
List,
- TYPE_CHECKING as _TYPE_CHECKING,
Text,
Type,
TypeVar,
@@ -124,7 +121,7 @@
s._utf8 = u
return s
- if _TYPE_CHECKING:
+ if pycompat.TYPE_CHECKING:
# pseudo implementation to help pytype see localstr() constructor
def __init__(self, u, l):
# type: (bytes, bytes) -> None
--- a/mercurial/logcmdutil.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/logcmdutil.py Tue Nov 19 23:49:05 2019 +0900
@@ -42,7 +42,7 @@
)
-if not globals():
+if pycompat.TYPE_CHECKING:
from typing import (
Any,
Tuple,
--- a/mercurial/mail.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/mail.py Tue Nov 19 23:49:05 2019 +0900
@@ -36,7 +36,7 @@
stringutil,
)
-if not globals(): # hide this from non-pytype users
+if pycompat.TYPE_CHECKING:
from typing import Any, List, Tuple, Union
# keep pyflakes happy
--- a/mercurial/pycompat.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/pycompat.py Tue Nov 19 23:49:05 2019 +0900
@@ -20,6 +20,12 @@
ispy3 = sys.version_info[0] >= 3
ispypy = '__pypy__' in sys.builtin_module_names
+TYPE_CHECKING = False
+
+if not globals(): # hide this from non-pytype users
+ import typing
+
+ TYPE_CHECKING = typing.TYPE_CHECKING
if not ispy3:
import cookielib
--- a/mercurial/state.py Tue Nov 19 23:19:57 2019 +0900
+++ b/mercurial/state.py Tue Nov 19 23:49:05 2019 +0900
@@ -23,11 +23,12 @@
from . import (
error,
+ pycompat,
util,
)
from .utils import cborutil
-if not globals():
+if pycompat.TYPE_CHECKING:
from typing import (
Any,
Dict,