summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-01-27 16:48:08 (GMT)
committerGitHub <noreply@github.com>2022-01-27 16:48:08 (GMT)
commitbfcb41420a326ec353740d8180ffbf402746fa33 (patch)
tree65480798a17cb5096033912cf178e19aa1199f90 /Lib/typing.py
parent486a4b382943ed4c965a0a36b177e8e0b083a6e5 (diff)
downloadcpython-bfcb41420a326ec353740d8180ffbf402746fa33.zip
cpython-bfcb41420a326ec353740d8180ffbf402746fa33.tar.gz
cpython-bfcb41420a326ec353740d8180ffbf402746fa33.tar.bz2
bpo-46539: Pass status of special typeforms to forward references (GH-30926)
Previously this didn't matter because there weren't any valid code paths that could trigger a type check with a special form, but after the bug fix for `Annotated` wrapping special forms it's now possible to annotate something like `Annotated['ClassVar[int]', (3, 4)]`. This change would also be needed for proposed future changes, such as allowing `ClassVar` and `Final` to nest each other in dataclasses. (cherry picked from commit ced50051bb752a7c1e616f4b0c001f37f0354f32) Co-authored-by: Gregory Beauregard <greg@greg.red>
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index aca3f7a..0ea389d 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -134,12 +134,12 @@ __all__ = [
# legitimate imports of those modules.
-def _type_convert(arg, module=None):
+def _type_convert(arg, module=None, *, allow_special_forms=False):
"""For converting None to type(None), and strings to ForwardRef."""
if arg is None:
return type(None)
if isinstance(arg, str):
- return ForwardRef(arg, module=module)
+ return ForwardRef(arg, module=module, is_class=allow_special_forms)
return arg
@@ -161,7 +161,7 @@ def _type_check(arg, msg, is_argument=True, module=None, *, allow_special_forms=
if is_argument:
invalid_generic_forms += (Final,)
- arg = _type_convert(arg, module=module)
+ arg = _type_convert(arg, module=module, allow_special_forms=allow_special_forms)
if (isinstance(arg, _GenericAlias) and
arg.__origin__ in invalid_generic_forms):
raise TypeError(f"{arg} is not valid as type argument")