8000 Use inspect constants · python/cpython@e0578fc · GitHub
[go: up one dir, main page]

Skip to content

Commit e0578fc

Browse files
committed
Use inspect constants
1 parent ce98c19 commit e0578fc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Lib/test/test_type_annotations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12
import textwrap
23
import types
34
import unittest
@@ -350,7 +351,7 @@ class X:
350351
self.assertIsInstance(annotate, types.FunctionType)
351352
self.assertEqual(annotate.__name__, f"<annotations of {obj.__name__}>")
352353
with self.assertRaises(AssertionError): # TODO NotImplementedError
353-
annotate(2)
354+
annotate(inspect.FORWARDREF)
354355
with self.assertRaises(AssertionError): # TODO NotImplementedError
355356
annotate(None)
356-
self.assertEqual(annotate(1), {"x": int})
357+
self.assertEqual(annotate(inspect.VALUE), {"x": int})

Lib/typing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import collections.abc
2525
import copyreg
2626
import functools
27+
import inspect
2728
import operator
2829
import sys
2930
import types
@@ -2973,7 +2974,7 @@ def __new__(cls, typename, bases, ns):
29732974
if "__annotations__" in ns:
29742975
types = ns["__annotations__"]
29752976
elif "__annotate__" in ns:
2976-
types = ns["__annotate__"](1)
2977+
types = ns["__annotate__"](inspect.VALUE)
29772978
else:
29782979
types = {}
29792980
default_names = []
@@ -3139,7 +3140,7 @@ def __new__(cls, name, bases, ns, total=True):
31393140
if "__annotations__" in ns:
31403141
own_annotations = ns["__annotations__"]
31413142
elif "__annotate__" in ns:
3142-
own_annotations = ns["__annotate__"](1)
3143+
own_annotations = ns["__annotate__"](inspect.VALUE)
31433144
else:
31443145
own_annotations = {}
31453146
msg = "TypedDict('Name', {f0: t0, f1: t1, ...}); each t must be a type"

0 commit comments

Comments
 (0)
0