summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNina Zakharenko <nzakharenko@gmail.com>2018-05-23 03:32:10 (GMT)
committerIvan Levkivskyi <levkivskyi@gmail.com>2018-05-23 03:32:10 (GMT)
commit0e61dffdbaf39ac5916ce431ff3b37db8faa1d2d (patch)
tree9743e7ce345d08d60b276a320c4c4cb1f29d21aa
parent8bb0b5b03cffa2a2e74f248ef479a9e7fbe95cf4 (diff)
downloadcpython-0e61dffdbaf39ac5916ce431ff3b37db8faa1d2d.zip
cpython-0e61dffdbaf39ac5916ce431ff3b37db8faa1d2d.tar.gz
cpython-0e61dffdbaf39ac5916ce431ff3b37db8faa1d2d.tar.bz2
Reverse the meaning of is_argument when used for type check (GH-7039)
-rw-r--r--Lib/typing.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 3e82c6b..18b04cf 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -106,7 +106,7 @@ __all__ = [
# legitimate imports of those modules.
-def _type_check(arg, msg, is_argument=False):
+def _type_check(arg, msg, is_argument=True):
"""Check that the argument is a type, and return it (internal helper).
As a special case, accept None and return type(None) instead. Also wrap strings
@@ -119,7 +119,7 @@ def _type_check(arg, msg, is_argument=False):
We append the repr() of the actual value (truncated to 100 chars).
"""
invalid_generic_forms = (Generic, _Protocol)
- if not is_argument:
+ if is_argument:
invalid_generic_forms = invalid_generic_forms + (ClassVar, )
if arg is None:
@@ -445,7 +445,7 @@ class ForwardRef(_Final, _root=True):
'__forward_evaluated__', '__forward_value__',
'__forward_is_argument__')
- def __init__(self, arg, is_argument=False):
+ def __init__(self, arg, is_argument=True):
if not isinstance(arg, str):
raise TypeError(f"Forward reference must be a string -- got {arg!r}")
try:
@@ -979,7 +979,7 @@ def get_type_hints(obj, globalns=None, localns=None):
if value is None:
value = type(None)
if isinstance(value, str):
- value = ForwardRef(value, is_argument=True)
+ value = ForwardRef(value, is_argument=False)
value = _eval_type(value, base_globals, localns)
hints[name] = value
return hints