summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/ast.rst25
-rw-r--r--Doc/whatsnew/3.13.rst15
-rw-r--r--Include/internal/pycore_global_objects_fini_generated.h1
-rw-r--r--Include/internal/pycore_global_strings.h1
-rw-r--r--Include/internal/pycore_runtime_init_generated.h1
-rw-r--r--Include/internal/pycore_unicodeobject_generated.h3
-rw-r--r--Lib/test/test_ast.py101
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2023-06-16-21-29-06.gh-issue-105858.Q7h0EV.rst8
-rwxr-xr-xParser/asdl_c.py238
-rw-r--r--Python/Python-ast.c4333
10 files changed, 4676 insertions, 50 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst
index c943c2f..d629393 100644
--- a/Doc/library/ast.rst
+++ b/Doc/library/ast.rst
@@ -103,20 +103,15 @@ Node classes
For example, to create and populate an :class:`ast.UnaryOp` node, you could
use ::
- node = ast.UnaryOp()
- node.op = ast.USub()
- node.operand = ast.Constant()
- node.operand.value = 5
- node.operand.lineno = 0
- node.operand.col_offset = 0
- node.lineno = 0
- node.col_offset = 0
-
- or the more compact ::
-
node = ast.UnaryOp(ast.USub(), ast.Constant(5, lineno=0, col_offset=0),
lineno=0, col_offset=0)
+ If a field that is optional in the grammar is omitted from the constructor,
+ it defaults to ``None``. If a list field is omitted, it defaults to the empty
+ list. If any other field is omitted, a :exc:`DeprecationWarning` is raised
+ and the AST node will not have this field. In Python 3.15, this condition will
+ raise an error.
+
.. versionchanged:: 3.8
Class :class:`ast.Constant` is now used for all constants.
@@ -140,6 +135,14 @@ Node classes
In the meantime, instantiating them will return an instance of
a different class.
+.. deprecated-removed:: 3.13 3.15
+
+ Previous versions of Python allowed the creation of AST nodes that were missing
+ required fields. Similarly, AST node constructors allowed arbitrary keyword
+ arguments that were set as attributes of the AST node, even if they did not
+ match any of the fields of the AST node. This behavior is deprecated and will
+ be removed in Python 3.15.
+
.. note::
The descriptions of the specific node classes displayed here
were initially adapted from the fantastic `Green Tree
diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst
index ca5a0e7..3a277d7 100644
--- a/Doc/whatsnew/3.13.rst
+++ b/Doc/whatsnew/3.13.rst
@@ -206,6 +206,21 @@ array
ast
---
+* The constructors of node types in the :mod:`ast` module are now stricter
+ in the arguments they accept, and have more intuitive behaviour when
+ arguments are omitted.
+
+ If an optional field on an AST node is not included as an argument when
+ constructing an instance, the field will now be set to ``None``. Similarly,
+ if a list field is omitted, that field will now be set to an empty list.
+ (Previously, in both cases, the attribute would be missing on the newly
+ constructed AST node instance.)
+
+ If other arguments are omitted, a :exc:`DeprecationWarning` is emitted.
+ This will cause an exception in Python 3.15. Similarly, passing a keyword
+ argument that does not map to a field on the AST node is now deprecated,
+ and will raise an exception in Python 3.15.
+
* :func:`ast.parse` now accepts an optional argument ``optimize``
which is passed on to the :func:`compile` built-in. This makes it
possible to obtain an optimized ``AST``.
diff --git a/Include/internal/pycore_global_objects_fini_generated.h b/Include/internal/pycore_global_objects_fini_generated.h
index 3253b52..e8b62bd 100644
--- a/Include/internal/pycore_global_objects_fini_generated.h
+++ b/Include/internal/pycore_global_objects_fini_generated.h
@@ -753,6 +753,7 @@ _PyStaticObjects_CheckRefcnt(PyInterpreterState *interp) {
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_check_retval_));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_dealloc_warn));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_feature_version));
+ _PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_field_types));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_fields_));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_finalizing));
_PyStaticObject_CheckRefcnt((PyObject *)&_Py_ID(_find_and_load));
diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h
index 8780f7e..b41f5c8 100644
--- a/Include/internal/pycore_global_strings.h
+++ b/Include/internal/pycore_global_strings.h
@@ -242,6 +242,7 @@ struct _Py_global_strings {
STRUCT_FOR_ID(_check_retval_)
STRUCT_FOR_ID(_dealloc_warn)
STRUCT_FOR_ID(_feature_version)
+ STRUCT_FOR_ID(_field_types)
STRUCT_FOR_ID(_fields_)
STRUCT_FOR_ID(_finalizing)
STRUCT_FOR_ID(_find_and_load)
diff --git a/Include/internal/pycore_runtime_init_generated.h b/Include/internal/pycore_runtime_init_generated.h
index a9d5148..016eae0 100644
--- a/Include/internal/pycore_runtime_init_generated.h
+++ b/Include/internal/pycore_runtime_init_generated.h
@@ -751,6 +751,7 @@ extern "C" {
INIT_ID(_check_retval_), \
INIT_ID(_dealloc_warn), \
INIT_ID(_feature_version), \
+ INIT_ID(_field_types), \
INIT_ID(_fields_), \
INIT_ID(_finalizing), \
INIT_ID(_find_and_load), \
diff --git a/Include/internal/pycore_unicodeobject_generated.h b/Include/internal/pycore_unicodeobject_generated.h
index f3b064e..64c4cf8 100644
--- a/Include/internal/pycore_unicodeobject_generated.h
+++ b/Include/internal/pycore_unicodeobject_generated.h
@@ -567,6 +567,9 @@ _PyUnicode_InitStaticStrings(PyInterpreterState *interp) {
string = &_Py_ID(_feature_version);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);
+ string = &_Py_ID(_field_types);
+ assert(_PyUnicode_CheckConsistency(string, 1));
+ _PyUnicode_InternInPlace(interp, &string);
string = &_Py_ID(_fields_);
assert(_PyUnicode_CheckConsistency(string, 1));
_PyUnicode_InternInPlace(interp, &string);
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index d49c149..7cecf31 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -525,17 +525,38 @@ class AST_Tests(unittest.TestCase):
if name == 'Index':
continue
if self._is_ast_node(name, item):
- x = item()
+ x = self._construct_ast_class(item)
if isinstance(x, ast.AST):
self.assertIs(type(x._fields), tuple)
+ def _construct_ast_class(self, cls):
+ kwargs = {}
+ for name, typ in cls.__annotations__.items():
+ if typ is str:
+ kwargs[name] = 'capybara'
+ elif typ is int:
+ kwargs[name] = 42
+ elif typ is object:
+ kwargs[name] = b'capybara'
+ elif isinstance(typ, type) and issubclass(typ, ast.AST):
+ kwargs[name] = self._construct_ast_class(typ)
+ return cls(**kwargs)
+
def test_arguments(self):
x = ast.arguments()
self.assertEqual(x._fields, ('posonlyargs', 'args', 'vararg', 'kwonlyargs',
'kw_defaults', 'kwarg', 'defaults'))
-
- with self.assertRaises(AttributeError):
- x.args
+ self.assertEqual(x.__annotations__, {
+ 'posonlyargs': list[ast.arg],
+ 'args': list[ast.arg],
+ 'vararg': ast.arg | None,
+ 'kwonlyargs': list[ast.arg],
+ 'kw_defaults': list[ast.expr],
+ 'kwarg': ast.arg | None,
+ 'defaults': list[ast.expr],
+ })
+
+ self.assertEqual(x.args, [])
self.assertIsNone(x.vararg)
x = ast.arguments(*range(1, 8))
@@ -551,7 +572,7 @@ class AST_Tests(unittest.TestCase):
self.assertEqual(x._fields, 666)
def test_field_attr_writable(self):
- x = ast.Constant()
+ x = ast.Constant(1)
# We can assign to _fields
x._fields = 666
self.assertEqual(x._fields, 666)
@@ -611,15 +632,22 @@ class AST_Tests(unittest.TestCase):
self.assertEqual([str(w.message) for w in wlog], [
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
+ "Constant.__init__ missing 1 required positional argument: 'value'. This will become "
+ 'an error in Python 3.15.',
'Attribute n is deprecated and will be removed in Python 3.14; use value instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
'Attribute n is deprecated and will be removed in Python 3.14; use value instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
+ "Constant.__init__ missing 1 required positional argument: 'value'. This will become "
+ 'an error in Python 3.15.',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
'Attribute n is deprecated and will be removed in Python 3.14; use value instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
+ "Constant.__init__ got an unexpected keyword argument 'foo'. Support for "
+ 'arbitrary keyword arguments is deprecated and will be removed in Python '
+ '3.15.',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
'Attribute n is deprecated and will be removed in Python 3.14; use value instead',
'ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead',
@@ -636,7 +664,8 @@ class AST_Tests(unittest.TestCase):
])
def test_classattrs(self):
- x = ast.Constant()
+ with self.assertWarns(DeprecationWarning):
+ x = ast.Constant()
self.assertEqual(x._fields, ('value', 'kind'))
with self.assertRaises(AttributeError):
@@ -651,7 +680,7 @@ class AST_Tests(unittest.TestCase):
with self.assertRaises(AttributeError):
x.foobar
- x = ast.Constant(lineno=2)
+ x = ast.Constant(lineno=2, value=3)
self.assertEqual(x.lineno, 2)
x = ast.Constant(42, lineno=0)
@@ -662,8 +691,9 @@ class AST_Tests(unittest.TestCase):
self.assertRaises(TypeError, ast.Constant, 1, None, 2)
self.assertRaises(TypeError, ast.Constant, 1, None, 2, lineno=0)
- # Arbitrary keyword arguments are supported
- self.assertEqual(ast.Constant(1, foo='bar').foo, 'bar')
+ # Arbitrary keyword arguments are supported (but deprecated)
+ with self.assertWarns(DeprecationWarning):
+ self.assertEqual(ast.Constant(1, foo='bar').foo, 'bar')
with self.assertRaisesRegex(TypeError, "Constant got multiple values for argument 'value'"):
ast.Constant(1, value=2)
@@ -815,11 +845,11 @@ class AST_Tests(unittest.TestCase):
assertBytesDeprecated(self.assertNotIsInstance, Constant('42'), Bytes)
assertNameConstantDeprecated(self.assertNotIsInstance, Constant(42), NameConstant)
assertEllipsisDeprecated(self.assertNotIsInstance, Constant(42), Ellipsis)
- assertNumDeprecated(self.assertNotIsInstance, Constant(), Num)
- assertStrDeprecated(self.assertNotIsInstance, Constant(), Str)
- assertBytesDeprecated(self.assertNotIsInstance, Constant(), Bytes)
- assertNameConstantDeprecated(self.assertNotIsInstance, Constant(), NameConstant)
- assertEllipsisDeprecated(self.assertNotIsInstance, Constant(), Ellipsis)
+ assertNumDeprecated(self.assertNotIsInstance, Constant(None), Num)
+ assertStrDeprecated(self.assertNotIsInstance, Constant(None), Str)
+ assertBytesDeprecated(self.assertNotIsInstance, Constant(None), Bytes)
+ assertNameConstantDeprecated(self.assertNotIsInstance, Constant(1), NameConstant)
+ assertEllipsisDeprecated(self.assertNotIsInstance, Constant(None), Ellipsis)
class S(str): pass
with assertStrDeprecated():
@@ -888,8 +918,9 @@ class AST_Tests(unittest.TestCase):
self.assertEqual(x.body, body)
def test_nodeclasses(self):
- # Zero arguments constructor explicitly allowed
- x = ast.BinOp()
+ # Zero arguments constructor explicitly allowed (but deprecated)
+ with self.assertWarns(DeprecationWarning):
+ x = ast.BinOp()
self.assertEqual(x._fields, ('left', 'op', 'right'))
# Random attribute allowed too
@@ -927,8 +958,9 @@ class AST_Tests(unittest.TestCase):
self.assertEqual(x.right, 3)
self.assertEqual(x.lineno, 0)
- # Random kwargs also allowed
- x = ast.BinOp(1, 2, 3, foobarbaz=42)
+ # Random kwargs also allowed (but deprecated)
+ with self.assertWarns(DeprecationWarning):
+ x = ast.BinOp(1, 2, 3, foobarbaz=42)
self.assertEqual(x.foobarbaz, 42)
def test_no_fields(self):
@@ -941,8 +973,9 @@ class AST_Tests(unittest.TestCase):
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
for ast in (compile(i, "?", "exec", 0x400) for i in exec_tests):
- ast2 = pickle.loads(pickle.dumps(ast, protocol))
- self.assertEqual(to_tuple(ast2), to_tuple(ast))
+ with self.subTest(ast=ast, protocol=protocol):
+ ast2 = pickle.loads(pickle.dumps(ast, protocol))
+ self.assertEqual(to_tuple(ast2), to_tuple(ast))
def test_invalid_sum(self):
pos = dict(lineno=2, col_offset=3)
@@ -1310,8 +1343,9 @@ Module(
'lineno=1, col_offset=4, end_lineno=1, end_col_offset=5), lineno=1, '
'col_offset=0, end_lineno=1, end_col_offset=5))'
)
- src = ast.Call(col_offset=1, lineno=1, end_lineno=1, end_col_offset=1)
- new = ast.copy_location(src, ast.Call(col_offset=None, lineno=None))
+ func = ast.Name('spam', ast.Load())
+ src = ast.Call(col_offset=1, lineno=1, end_lineno=1, end_col_offset=1, func=func)
+ new = ast.copy_location(src, ast.Call(col_offset=None, lineno=None, func=func))
self.assertIsNone(new.end_lineno)
self.assertIsNone(new.end_col_offset)
self.assertEqual(new.lineno, 1)
@@ -1570,15 +1604,15 @@ Module(
self.assertIn('sleep', ns)
def test_recursion_direct(self):
- e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
+ e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
e.operand = e
with self.assertRaises(RecursionError):
with support.infinite_recursion():
compile(ast.Expression(e), "<test>", "eval")
def test_recursion_indirect(self):
- e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
- f = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0)
+ e = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
+ f = ast.UnaryOp(op=ast.Not(), lineno=0, col_offset=0, operand=ast.Constant(1))
e.operand = f
f.operand = e
with self.assertRaises(RecursionError):
@@ -2866,6 +2900,23 @@ class NodeTransformerTests(ASTTestMixin, BaseNodeVisitorCases, unittest.TestCase
self.assertASTTransformation(PrintToLog, code, expected)
+class ASTConstructorTests(unittest.TestCase):
+ """Test the autogenerated constructors for AST nodes."""
+
+ def test_FunctionDef(self):
+ args = ast.arguments()
+ self.assertEqual(args.args, [])
+ self.assertEqual(args.posonlyargs, [])
+ with self.assertWarnsRegex(DeprecationWarning,
+ r"FunctionDef\.__init__ missing 1 required positional argument: 'name'"):
+ node = ast.FunctionDef(args=args)
+ self.assertFalse(hasattr(node, "name"))
+ self.assertEqual(node.decorator_list, [])
+ node = ast.FunctionDef(name='foo', args=args)
+ self.assertEqual(node.name, 'foo')
+ self.assertEqual(node.decorator_list, [])
+
+
@support.cpython_only
class ModuleStateTests(unittest.TestCase):
# bpo-41194, bpo-41261, bpo-41631: The _ast module uses a global state.
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-06-16-21-29-06.gh-issue-105858.Q7h0EV.rst b/Misc/NEWS.d/next/Core and Builtins/2023-06-16-21-29-06.gh-issue-105858.Q7h0EV.rst
new file mode 100644
index 0000000..9338f66
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-06-16-21-29-06.gh-issue-105858.Q7h0EV.rst
@@ -0,0 +1,8 @@
+Improve the constructors for :mod:`ast` nodes. Arguments of list types now
+default to an empty list if omitted, and optional fields default to ``None``.
+AST nodes now have an
+``__annotations__`` attribute with the expected types of their attributes.
+Passing unrecognized extra arguments to AST nodes is deprecated and will
+become an error in Python 3.15. Omitting a required argument to an AST node
+is deprecated and will become an error in Python 3.15. Patch by Jelle
+Zijlstra.
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index ce92672..865fd76 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -15,6 +15,13 @@ TABSIZE = 4
MAX_COL = 80
AUTOGEN_MESSAGE = "// File automatically generated by {}.\n\n"
+builtin_type_to_c_type = {
+ "identifier": "PyUnicode_Type",
+ "string": "PyUnicode_Type",
+ "int": "PyLong_Type",
+ "constant": "PyBaseObject_Type",
+}
+
def get_c_type(name):
"""Return a string for the C name of the type.
@@ -764,6 +771,67 @@ class PyTypesDeclareVisitor(PickleVisitor):
self.emit("};",0)
+class AnnotationsVisitor(PickleVisitor):
+ def visitModule(self, mod):
+ self.file.write(textwrap.dedent('''
+ static int
+ add_ast_annotations(struct ast_state *state)
+ {
+ bool cond;
+ '''))
+ for dfn in mod.dfns:
+ self.visit(dfn)
+ self.file.write(textwrap.dedent('''
+ return 1;
+ }
+ '''))
+
+ def visitProduct(self, prod, name):
+ self.emit_annotations(name, prod.fields)
+
+ def visitSum(self, sum, name):
+ for t in sum.types:
+ self.visitConstructor(t, name)
+
+ def visitConstructor(self, cons, name):
+ self.emit_annotations(cons.name, cons.fields)
+
+ def emit_annotations(self, name, fields):
+ self.emit(f"PyObject *{name}_annotations = PyDict_New();", 1)
+ self.emit(f"if (!{name}_annotations) return 0;", 1)
+ for field in fields:
+ self.emit("{", 1)
+ if field.type in builtin_type_to_c_type:
+ self.emit(f"PyObject *type = (PyObject *)&{builtin_type_to_c_type[field.type]};", 2)
+ else:
+ self.emit(f"PyObject *type = state->{field.type}_type;", 2)
+ if field.opt:
+ self.emit("type = _Py_union_type_or(type, Py_None);", 2)
+ self.emit("cond = type != NULL;", 2)
+ self.emit_annotations_error(name, 2)
+ elif field.seq:
+ self.emit("type = Py_GenericAlias((PyObject *)&PyList_Type, type);", 2)
+ self.emit("cond = type != NULL;", 2)
+ self.emit_annotations_error(name, 2)
+ else:
+ self.emit("Py_INCREF(type);", 2)
+ self.emit(f"cond = PyDict_SetItemString({name}_annotations, \"{field.name}\", type) == 0;", 2)
+ self.emit("Py_DECREF(type);", 2)
+ self.emit_annotations_error(name, 2)
+ self.emit("}", 1)
+ self.emit(f'cond = PyObject_SetAttrString(state->{name}_type, "_field_types", {name}_annotations) == 0;', 1)
+ self.emit_annotations_error(name, 1)
+ self.emit(f'cond = PyObject_SetAttrString(state->{name}_type, "__annotations__", {name}_annotations) == 0;', 1)
+ self.emit_annotations_error(name, 1)
+ self.emit(f"Py_DECREF({name}_annotations);", 1)
+
+ def emit_annotations_error(self, name, depth):
+ self.emit("if (!cond) {", depth)
+ self.emit(f"Py_DECREF({name}_annotations);", depth + 1)
+ self.emit("return 0;", depth + 1)
+ self.emit("}", depth)
+
+
class PyTypesVisitor(PickleVisitor):
def visitModule(self, mod):
@@ -812,7 +880,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t i, numfields = 0;
int res = -1;
- PyObject *key, *value, *fields;
+ PyObject *key, *value, *fields, *remaining_fields = NULL;
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
goto cleanup;
}
@@ -821,6 +889,13 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
if (numfields == -1) {
goto cleanup;
}
+ remaining_fields = PySet_New(fields);
+ }
+ else {
+ remaining_fields = PySet_New(NULL);
+ }
+ if (remaining_fields == NULL) {
+ goto cleanup;
}
res = 0; /* if no error occurs, this stays 0 to the end */
@@ -840,6 +915,11 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
goto cleanup;
}
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
+ if (PySet_Discard(remaining_fields, name) < 0) {
+ res = -1;
+ Py_DECREF(name);
+ goto cleanup;
+ }
Py_DECREF(name);
if (res < 0) {
goto cleanup;
@@ -852,13 +932,14 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
if (contains == -1) {
res = -1;
goto cleanup;
- } else if (contains == 1) {
- Py_ssize_t p = PySequence_Index(fields, key);
+ }
+ else if (contains == 1) {
+ int p = PySet_Discard(remaining_fields, key);
if (p == -1) {
res = -1;
goto cleanup;
}
- if (p < PyTuple_GET_SIZE(args)) {
+ if (p == 0) {
PyErr_Format(PyExc_TypeError,
"%.400s got multiple values for argument '%U'",
Py_TYPE(self)->tp_name, key);
@@ -866,15 +947,91 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
goto cleanup;
}
}
+ else if (
+ PyUnicode_CompareWithASCIIString(key, "lineno") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "col_offset") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "end_lineno") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "end_col_offset") != 0
+ ) {
+ if (PyErr_WarnFormat(
+ PyExc_DeprecationWarning, 1,
+ "%.400s.__init__ got an unexpected keyword argument '%U'. "
+ "Support for arbitrary keyword arguments is deprecated "
+ "and will be removed in Python 3.15.",
+ Py_TYPE(self)->tp_name, key
+ ) < 0) {
+ res = -1;
+ goto cleanup;
+ }
+ }
res = PyObject_SetAttr(self, key, value);
if (res < 0) {
goto cleanup;
}
}
}
+ Py_ssize_t size = PySet_Size(remaining_fields);
+ PyObject *field_types = NULL, *remaining_list = NULL;
+ if (size > 0) {
+ if (!PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
+ &field_types)) {
+ res = -1;
+ goto cleanup;
+ }
+ remaining_list = PySequence_List(remaining_fields);
+ if (!remaining_list) {
+ goto set_remaining_cleanup;
+ }
+ for (Py_ssize_t i = 0; i < size; i++) {
+ PyObject *name = PyList_GET_ITEM(remaining_list, i);
+ PyObject *type = PyDict_GetItemWithError(field_types, name);
+ if (!type) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetObject(PyExc_KeyError, name);
+ }
+ goto set_remaining_cleanup;
+ }
+ if (_PyUnion_Check(type)) {
+ // optional field
+ // do nothing, we'll have set a None default on the class
+ }
+ else if (Py_IS_TYPE(type, &Py_GenericAliasType)) {
+ // list field
+ PyObject *empty = PyList_New(0);
+ if (!empty) {
+ goto set_remaining_cleanup;
+ }
+ res = PyObject_SetAttr(self, name, empty);
+ Py_DECREF(empty);
+ if (res < 0) {
+ goto set_remaining_cleanup;
+ }
+ }
+ else {
+ // simple field (e.g., identifier)
+ if (PyErr_WarnFormat(
+ PyExc_DeprecationWarning, 1,
+ "%.400s.__init__ missing 1 required positional argument: '%U'. "
+ "This will become an error in Python 3.15.",
+ Py_TYPE(self)->tp_name, name
+ ) < 0) {
+ res = -1;
+ goto cleanup;
+ }
+ }
+ }
+ Py_DECREF(remaining_list);
+ Py_DECREF(field_types);
+ }
cleanup:
Py_XDECREF(fields);
+ Py_XDECREF(remaining_fields);
return res;
+ set_remaining_cleanup:
+ Py_XDECREF(remaining_list);
+ Py_XDECREF(field_types);
+ res = -1;
+ goto cleanup;
}
/* Pickling support */
@@ -886,14 +1043,75 @@ ast_type_reduce(PyObject *self, PyObject *unused)
return NULL;
}
- PyObject *dict;
+ PyObject *dict = NULL, *fields = NULL, *remaining_fields = NULL,
+ *remaining_dict = NULL, *positional_args = NULL;
if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
return NULL;
}
+ PyObject *result = NULL;
if (dict) {
- return Py_BuildValue("O()N", Py_TYPE(self), dict);
+ // Serialize the fields as positional args if possible, because if we
+ // serialize them as a dict, during unpickling they are set only *after*
+ // the object is constructed, which will now trigger a DeprecationWarning
+ // if the AST type has required fields.
+ if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
+ goto cleanup;
+ }
+ if (fields) {
+ Py_ssize_t numfields = PySequence_Size(fields);
+ if (numfields == -1) {
+ Py_DECREF(dict);
+ goto cleanup;
+ }
+ remaining_dict = PyDict_Copy(dict);
+ Py_DECREF(dict);
+ if (!remaining_dict) {
+ goto cleanup;
+ }
+ positional_args = PyList_New(0);
+ if (!positional_args) {
+ goto cleanup;
+ }
+ for (Py_ssize_t i = 0; i < numfields; i++) {
+ PyObject *name = PySequence_GetItem(fields, i);
+ if (!name) {
+ goto cleanup;
+ }
+ PyObject *value = PyDict_GetItemWithError(remaining_dict, name);
+ if (!value) {
+ if (PyErr_Occurred()) {
+ goto cleanup;
+ }
+ break;
+ }
+ if (PyList_Append(positional_args, value) < 0) {
+ goto cleanup;
+ }
+ if (PyDict_DelItem(remaining_dict, name) < 0) {
+ goto cleanup;
+ }
+ Py_DECREF(name);
+ }
+ PyObject *args_tuple = PyList_AsTuple(positional_args);
+ if (!args_tuple) {
+ goto cleanup;
+ }
+ result = Py_BuildValue("ONO", Py_TYPE(self), args_tuple,
+ remaining_dict);
+ }
+ else {
+ result = Py_BuildValue("O()N", Py_TYPE(self), dict);
+ }
+ }
+ else {
+ result = Py_BuildValue("O()", Py_TYPE(self));
}
- return Py_BuildValue("O()", Py_TYPE(self));
+cleanup:
+ Py_XDECREF(fields);
+ Py_XDECREF(remaining_fields);
+ Py_XDECREF(remaining_dict);
+ Py_XDECREF(positional_args);
+ return result;
}
static PyMemberDef ast_type_members[] = {
@@ -1117,6 +1335,9 @@ static int add_ast_fields(struct ast_state *state)
for dfn in mod.dfns:
self.visit(dfn)
self.file.write(textwrap.dedent('''
+ if (!add_ast_annotations(state)) {
+ return -1;
+ }
return 0;
}
'''))
@@ -1534,6 +1755,8 @@ def generate_module_def(mod, metadata, f, internal_h):
#include "pycore_lock.h" // _PyOnceFlag
#include "pycore_interp.h" // _PyInterpreterState.ast
#include "pycore_pystate.h" // _PyInterpreterState_GET()
+ #include "pycore_unionobject.h" // _Py_union_type_or
+ #include "structmember.h"
#include <stddef.h>
struct validator {
@@ -1651,6 +1874,7 @@ def write_source(mod, metadata, f, internal_h_file):
v = ChainOfVisitors(
SequenceConstructorVisitor(f),
PyTypesDeclareVisitor(f),
+ AnnotationsVisitor(f),
PyTypesVisitor(f),
Obj2ModPrototypeVisitor(f),
FunctionVisitor(f),
diff --git a/Python/Python-ast.c b/Python/Python-ast.c
index d77e986..4638749 100644
--- a/Python/Python-ast.c
+++ b/Python/Python-ast.c
@@ -7,6 +7,8 @@
#include "pycore_lock.h" // _PyOnceFlag
#include "pycore_interp.h" // _PyInterpreterState.ast
#include "pycore_pystate.h" // _PyInterpreterState_GET()
+#include "pycore_unionobject.h" // _Py_union_type_or
+#include "structmember.h"
#include <stddef.h>
struct validator {
@@ -816,6 +818,4170 @@ static const char * const TypeVarTuple_fields[]={
};
+static int
+add_ast_annotations(struct ast_state *state)
+{
+ bool cond;
+ PyObject *Module_annotations = PyDict_New();
+ if (!Module_annotations) return 0;
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Module_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->type_ignore_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Module_annotations, "type_ignores", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Module_type, "_field_types",
+ Module_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Module_type, "__annotations__",
+ Module_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Module_annotations);
+ return 0;
+ }
+ Py_DECREF(Module_annotations);
+ PyObject *Interactive_annotations = PyDict_New();
+ if (!Interactive_annotations) return 0;
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Interactive_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Interactive_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Interactive_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Interactive_type, "_field_types",
+ Interactive_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Interactive_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Interactive_type, "__annotations__",
+ Interactive_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Interactive_annotations);
+ return 0;
+ }
+ Py_DECREF(Interactive_annotations);
+ PyObject *Expression_annotations = PyDict_New();
+ if (!Expression_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Expression_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Expression_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Expression_type, "_field_types",
+ Expression_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Expression_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Expression_type, "__annotations__",
+ Expression_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Expression_annotations);
+ return 0;
+ }
+ Py_DECREF(Expression_annotations);
+ PyObject *FunctionType_annotations = PyDict_New();
+ if (!FunctionType_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionType_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionType_annotations, "argtypes", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionType_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(FunctionType_annotations, "returns", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionType_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->FunctionType_type, "_field_types",
+ FunctionType_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FunctionType_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->FunctionType_type, "__annotations__",
+ FunctionType_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FunctionType_annotations);
+ return 0;
+ }
+ Py_DECREF(FunctionType_annotations);
+ PyObject *FunctionDef_annotations = PyDict_New();
+ if (!FunctionDef_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(FunctionDef_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arguments_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(FunctionDef_annotations, "args", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionDef_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionDef_annotations, "decorator_list",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionDef_annotations, "returns", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionDef_annotations, "type_comment",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->type_param_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FunctionDef_annotations, "type_params",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->FunctionDef_type, "_field_types",
+ FunctionDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->FunctionDef_type, "__annotations__",
+ FunctionDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FunctionDef_annotations);
+ return 0;
+ }
+ Py_DECREF(FunctionDef_annotations);
+ PyObject *AsyncFunctionDef_annotations = PyDict_New();
+ if (!AsyncFunctionDef_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "name", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arguments_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "args", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "body", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
+ "decorator_list", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations, "returns",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
+ "type_comment", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->type_param_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFunctionDef_annotations,
+ "type_params", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->AsyncFunctionDef_type, "_field_types",
+ AsyncFunctionDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->AsyncFunctionDef_type,
+ "__annotations__",
+ AsyncFunctionDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncFunctionDef_annotations);
+ return 0;
+ }
+ Py_DECREF(AsyncFunctionDef_annotations);
+ PyObject *ClassDef_annotations = PyDict_New();
+ if (!ClassDef_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(ClassDef_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ClassDef_annotations, "bases", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->keyword_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ClassDef_annotations, "keywords", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ClassDef_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ClassDef_annotations, "decorator_list",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->type_param_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ClassDef_annotations, "type_params", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->ClassDef_type, "_field_types",
+ ClassDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->ClassDef_type, "__annotations__",
+ ClassDef_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ClassDef_annotations);
+ return 0;
+ }
+ Py_DECREF(ClassDef_annotations);
+ PyObject *Return_annotations = PyDict_New();
+ if (!Return_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Return_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Return_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Return_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Return_type, "_field_types",
+ Return_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Return_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Return_type, "__annotations__",
+ Return_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Return_annotations);
+ return 0;
+ }
+ Py_DECREF(Return_annotations);
+ PyObject *Delete_annotations = PyDict_New();
+ if (!Delete_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Delete_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Delete_annotations, "targets", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Delete_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Delete_type, "_field_types",
+ Delete_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Delete_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Delete_type, "__annotations__",
+ Delete_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Delete_annotations);
+ return 0;
+ }
+ Py_DECREF(Delete_annotations);
+ PyObject *Assign_annotations = PyDict_New();
+ if (!Assign_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Assign_annotations, "targets", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Assign_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Assign_annotations, "type_comment", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Assign_type, "_field_types",
+ Assign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Assign_type, "__annotations__",
+ Assign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Assign_annotations);
+ return 0;
+ }
+ Py_DECREF(Assign_annotations);
+ PyObject *TypeAlias_annotations = PyDict_New();
+ if (!TypeAlias_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeAlias_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->type_param_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TypeAlias_annotations, "type_params", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeAlias_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->TypeAlias_type, "_field_types",
+ TypeAlias_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->TypeAlias_type, "__annotations__",
+ TypeAlias_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeAlias_annotations);
+ return 0;
+ }
+ Py_DECREF(TypeAlias_annotations);
+ PyObject *AugAssign_annotations = PyDict_New();
+ if (!AugAssign_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AugAssign_annotations, "target", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AugAssign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->operator_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AugAssign_annotations, "op", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AugAssign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AugAssign_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AugAssign_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->AugAssign_type, "_field_types",
+ AugAssign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AugAssign_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->AugAssign_type, "__annotations__",
+ AugAssign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AugAssign_annotations);
+ return 0;
+ }
+ Py_DECREF(AugAssign_annotations);
+ PyObject *AnnAssign_annotations = PyDict_New();
+ if (!AnnAssign_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AnnAssign_annotations, "target", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AnnAssign_annotations, "annotation", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AnnAssign_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyLong_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AnnAssign_annotations, "simple", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->AnnAssign_type, "_field_types",
+ AnnAssign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->AnnAssign_type, "__annotations__",
+ AnnAssign_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AnnAssign_annotations);
+ return 0;
+ }
+ Py_DECREF(AnnAssign_annotations);
+ PyObject *For_annotations = PyDict_New();
+ if (!For_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(For_annotations, "target", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(For_annotations, "iter", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(For_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(For_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(For_annotations, "type_comment", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->For_type, "_field_types",
+ For_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->For_type, "__annotations__",
+ For_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(For_annotations);
+ return 0;
+ }
+ Py_DECREF(For_annotations);
+ PyObject *AsyncFor_annotations = PyDict_New();
+ if (!AsyncFor_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AsyncFor_annotations, "target", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(AsyncFor_annotations, "iter", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFor_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFor_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncFor_annotations, "type_comment", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->AsyncFor_type, "_field_types",
+ AsyncFor_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->AsyncFor_type, "__annotations__",
+ AsyncFor_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncFor_annotations);
+ return 0;
+ }
+ Py_DECREF(AsyncFor_annotations);
+ PyObject *While_annotations = PyDict_New();
+ if (!While_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(While_annotations, "test", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(While_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(While_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->While_type, "_field_types",
+ While_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->While_type, "__annotations__",
+ While_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(While_annotations);
+ return 0;
+ }
+ Py_DECREF(While_annotations);
+ PyObject *If_annotations = PyDict_New();
+ if (!If_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(If_annotations, "test", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(If_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(If_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->If_type, "_field_types",
+ If_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->If_type, "__annotations__",
+ If_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(If_annotations);
+ return 0;
+ }
+ Py_DECREF(If_annotations);
+ PyObject *With_annotations = PyDict_New();
+ if (!With_annotations) return 0;
+ {
+ PyObject *type = state->withitem_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(With_annotations, "items", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(With_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(With_annotations, "type_comment", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->With_type, "_field_types",
+ With_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->With_type, "__annotations__",
+ With_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(With_annotations);
+ return 0;
+ }
+ Py_DECREF(With_annotations);
+ PyObject *AsyncWith_annotations = PyDict_New();
+ if (!AsyncWith_annotations) return 0;
+ {
+ PyObject *type = state->withitem_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncWith_annotations, "items", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncWith_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(AsyncWith_annotations, "type_comment",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->AsyncWith_type, "_field_types",
+ AsyncWith_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->AsyncWith_type, "__annotations__",
+ AsyncWith_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(AsyncWith_annotations);
+ return 0;
+ }
+ Py_DECREF(AsyncWith_annotations);
+ PyObject *Match_annotations = PyDict_New();
+ if (!Match_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Match_annotations, "subject", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Match_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->match_case_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Match_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Match_annotations, "cases", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Match_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Match_type, "_field_types",
+ Match_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Match_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Match_type, "__annotations__",
+ Match_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Match_annotations);
+ return 0;
+ }
+ Py_DECREF(Match_annotations);
+ PyObject *Raise_annotations = PyDict_New();
+ if (!Raise_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Raise_annotations, "exc", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Raise_annotations, "cause", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Raise_type, "_field_types",
+ Raise_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Raise_type, "__annotations__",
+ Raise_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Raise_annotations);
+ return 0;
+ }
+ Py_DECREF(Raise_annotations);
+ PyObject *Try_annotations = PyDict_New();
+ if (!Try_annotations) return 0;
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Try_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->excepthandler_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Try_annotations, "handlers", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Try_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Try_annotations, "finalbody", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Try_type, "_field_types",
+ Try_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Try_type, "__annotations__",
+ Try_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Try_annotations);
+ return 0;
+ }
+ Py_DECREF(Try_annotations);
+ PyObject *TryStar_annotations = PyDict_New();
+ if (!TryStar_annotations) return 0;
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TryStar_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->excepthandler_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TryStar_annotations, "handlers", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TryStar_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TryStar_annotations, "finalbody", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->TryStar_type, "_field_types",
+ TryStar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->TryStar_type, "__annotations__",
+ TryStar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TryStar_annotations);
+ return 0;
+ }
+ Py_DECREF(TryStar_annotations);
+ PyObject *Assert_annotations = PyDict_New();
+ if (!Assert_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Assert_annotations, "test", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Assert_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Assert_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Assert_annotations, "msg", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Assert_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Assert_type, "_field_types",
+ Assert_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Assert_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Assert_type, "__annotations__",
+ Assert_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Assert_annotations);
+ return 0;
+ }
+ Py_DECREF(Assert_annotations);
+ PyObject *Import_annotations = PyDict_New();
+ if (!Import_annotations) return 0;
+ {
+ PyObject *type = state->alias_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Import_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Import_annotations, "names", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Import_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Import_type, "_field_types",
+ Import_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Import_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Import_type, "__annotations__",
+ Import_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Import_annotations);
+ return 0;
+ }
+ Py_DECREF(Import_annotations);
+ PyObject *ImportFrom_annotations = PyDict_New();
+ if (!ImportFrom_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ImportFrom_annotations, "module", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->alias_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ImportFrom_annotations, "names", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyLong_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ImportFrom_annotations, "level", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->ImportFrom_type, "_field_types",
+ ImportFrom_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->ImportFrom_type, "__annotations__",
+ ImportFrom_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ImportFrom_annotations);
+ return 0;
+ }
+ Py_DECREF(ImportFrom_annotations);
+ PyObject *Global_annotations = PyDict_New();
+ if (!Global_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Global_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Global_annotations, "names", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Global_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Global_type, "_field_types",
+ Global_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Global_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Global_type, "__annotations__",
+ Global_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Global_annotations);
+ return 0;
+ }
+ Py_DECREF(Global_annotations);
+ PyObject *Nonlocal_annotations = PyDict_New();
+ if (!Nonlocal_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Nonlocal_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Nonlocal_annotations, "names", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Nonlocal_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Nonlocal_type, "_field_types",
+ Nonlocal_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Nonlocal_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Nonlocal_type, "__annotations__",
+ Nonlocal_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Nonlocal_annotations);
+ return 0;
+ }
+ Py_DECREF(Nonlocal_annotations);
+ PyObject *Expr_annotations = PyDict_New();
+ if (!Expr_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Expr_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Expr_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Expr_type, "_field_types",
+ Expr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Expr_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Expr_type, "__annotations__",
+ Expr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Expr_annotations);
+ return 0;
+ }
+ Py_DECREF(Expr_annotations);
+ PyObject *Pass_annotations = PyDict_New();
+ if (!Pass_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Pass_type, "_field_types",
+ Pass_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Pass_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Pass_type, "__annotations__",
+ Pass_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Pass_annotations);
+ return 0;
+ }
+ Py_DECREF(Pass_annotations);
+ PyObject *Break_annotations = PyDict_New();
+ if (!Break_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Break_type, "_field_types",
+ Break_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Break_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Break_type, "__annotations__",
+ Break_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Break_annotations);
+ return 0;
+ }
+ Py_DECREF(Break_annotations);
+ PyObject *Continue_annotations = PyDict_New();
+ if (!Continue_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Continue_type, "_field_types",
+ Continue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Continue_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Continue_type, "__annotations__",
+ Continue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Continue_annotations);
+ return 0;
+ }
+ Py_DECREF(Continue_annotations);
+ PyObject *BoolOp_annotations = PyDict_New();
+ if (!BoolOp_annotations) return 0;
+ {
+ PyObject *type = state->boolop_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(BoolOp_annotations, "op", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(BoolOp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(BoolOp_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(BoolOp_annotations, "values", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(BoolOp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->BoolOp_type, "_field_types",
+ BoolOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BoolOp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->BoolOp_type, "__annotations__",
+ BoolOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BoolOp_annotations);
+ return 0;
+ }
+ Py_DECREF(BoolOp_annotations);
+ PyObject *NamedExpr_annotations = PyDict_New();
+ if (!NamedExpr_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(NamedExpr_annotations, "target", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(NamedExpr_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(NamedExpr_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(NamedExpr_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->NamedExpr_type, "_field_types",
+ NamedExpr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NamedExpr_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->NamedExpr_type, "__annotations__",
+ NamedExpr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NamedExpr_annotations);
+ return 0;
+ }
+ Py_DECREF(NamedExpr_annotations);
+ PyObject *BinOp_annotations = PyDict_New();
+ if (!BinOp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(BinOp_annotations, "left", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(BinOp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->operator_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(BinOp_annotations, "op", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(BinOp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(BinOp_annotations, "right", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(BinOp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->BinOp_type, "_field_types",
+ BinOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BinOp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->BinOp_type, "__annotations__",
+ BinOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BinOp_annotations);
+ return 0;
+ }
+ Py_DECREF(BinOp_annotations);
+ PyObject *UnaryOp_annotations = PyDict_New();
+ if (!UnaryOp_annotations) return 0;
+ {
+ PyObject *type = state->unaryop_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(UnaryOp_annotations, "op", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(UnaryOp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(UnaryOp_annotations, "operand", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(UnaryOp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->UnaryOp_type, "_field_types",
+ UnaryOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(UnaryOp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->UnaryOp_type, "__annotations__",
+ UnaryOp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(UnaryOp_annotations);
+ return 0;
+ }
+ Py_DECREF(UnaryOp_annotations);
+ PyObject *Lambda_annotations = PyDict_New();
+ if (!Lambda_annotations) return 0;
+ {
+ PyObject *type = state->arguments_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Lambda_annotations, "args", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Lambda_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Lambda_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Lambda_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Lambda_type, "_field_types",
+ Lambda_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Lambda_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Lambda_type, "__annotations__",
+ Lambda_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Lambda_annotations);
+ return 0;
+ }
+ Py_DECREF(Lambda_annotations);
+ PyObject *IfExp_annotations = PyDict_New();
+ if (!IfExp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(IfExp_annotations, "test", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(IfExp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(IfExp_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(IfExp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(IfExp_annotations, "orelse", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(IfExp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->IfExp_type, "_field_types",
+ IfExp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(IfExp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->IfExp_type, "__annotations__",
+ IfExp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(IfExp_annotations);
+ return 0;
+ }
+ Py_DECREF(IfExp_annotations);
+ PyObject *Dict_annotations = PyDict_New();
+ if (!Dict_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Dict_annotations, "keys", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Dict_annotations, "values", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Dict_type, "_field_types",
+ Dict_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Dict_type, "__annotations__",
+ Dict_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Dict_annotations);
+ return 0;
+ }
+ Py_DECREF(Dict_annotations);
+ PyObject *Set_annotations = PyDict_New();
+ if (!Set_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Set_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Set_annotations, "elts", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Set_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Set_type, "_field_types",
+ Set_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Set_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Set_type, "__annotations__",
+ Set_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Set_annotations);
+ return 0;
+ }
+ Py_DECREF(Set_annotations);
+ PyObject *ListComp_annotations = PyDict_New();
+ if (!ListComp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(ListComp_annotations, "elt", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ListComp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->comprehension_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ListComp_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ListComp_annotations, "generators", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ListComp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->ListComp_type, "_field_types",
+ ListComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ListComp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->ListComp_type, "__annotations__",
+ ListComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ListComp_annotations);
+ return 0;
+ }
+ Py_DECREF(ListComp_annotations);
+ PyObject *SetComp_annotations = PyDict_New();
+ if (!SetComp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(SetComp_annotations, "elt", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(SetComp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->comprehension_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(SetComp_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(SetComp_annotations, "generators", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(SetComp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->SetComp_type, "_field_types",
+ SetComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(SetComp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->SetComp_type, "__annotations__",
+ SetComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(SetComp_annotations);
+ return 0;
+ }
+ Py_DECREF(SetComp_annotations);
+ PyObject *DictComp_annotations = PyDict_New();
+ if (!DictComp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(DictComp_annotations, "key", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(DictComp_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->comprehension_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(DictComp_annotations, "generators", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->DictComp_type, "_field_types",
+ DictComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->DictComp_type, "__annotations__",
+ DictComp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(DictComp_annotations);
+ return 0;
+ }
+ Py_DECREF(DictComp_annotations);
+ PyObject *GeneratorExp_annotations = PyDict_New();
+ if (!GeneratorExp_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(GeneratorExp_annotations, "elt", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(GeneratorExp_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->comprehension_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(GeneratorExp_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(GeneratorExp_annotations, "generators",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(GeneratorExp_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->GeneratorExp_type, "_field_types",
+ GeneratorExp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(GeneratorExp_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->GeneratorExp_type, "__annotations__",
+ GeneratorExp_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(GeneratorExp_annotations);
+ return 0;
+ }
+ Py_DECREF(GeneratorExp_annotations);
+ PyObject *Await_annotations = PyDict_New();
+ if (!Await_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Await_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Await_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Await_type, "_field_types",
+ Await_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Await_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Await_type, "__annotations__",
+ Await_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Await_annotations);
+ return 0;
+ }
+ Py_DECREF(Await_annotations);
+ PyObject *Yield_annotations = PyDict_New();
+ if (!Yield_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Yield_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Yield_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Yield_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Yield_type, "_field_types",
+ Yield_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Yield_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Yield_type, "__annotations__",
+ Yield_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Yield_annotations);
+ return 0;
+ }
+ Py_DECREF(Yield_annotations);
+ PyObject *YieldFrom_annotations = PyDict_New();
+ if (!YieldFrom_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(YieldFrom_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(YieldFrom_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->YieldFrom_type, "_field_types",
+ YieldFrom_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(YieldFrom_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->YieldFrom_type, "__annotations__",
+ YieldFrom_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(YieldFrom_annotations);
+ return 0;
+ }
+ Py_DECREF(YieldFrom_annotations);
+ PyObject *Compare_annotations = PyDict_New();
+ if (!Compare_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Compare_annotations, "left", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->cmpop_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Compare_annotations, "ops", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Compare_annotations, "comparators", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Compare_type, "_field_types",
+ Compare_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Compare_type, "__annotations__",
+ Compare_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Compare_annotations);
+ return 0;
+ }
+ Py_DECREF(Compare_annotations);
+ PyObject *Call_annotations = PyDict_New();
+ if (!Call_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Call_annotations, "func", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Call_annotations, "args", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->keyword_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Call_annotations, "keywords", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Call_type, "_field_types",
+ Call_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Call_type, "__annotations__",
+ Call_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Call_annotations);
+ return 0;
+ }
+ Py_DECREF(Call_annotations);
+ PyObject *FormattedValue_annotations = PyDict_New();
+ if (!FormattedValue_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(FormattedValue_annotations, "value", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyLong_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(FormattedValue_annotations, "conversion",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(FormattedValue_annotations, "format_spec",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->FormattedValue_type, "_field_types",
+ FormattedValue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->FormattedValue_type,
+ "__annotations__",
+ FormattedValue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FormattedValue_annotations);
+ return 0;
+ }
+ Py_DECREF(FormattedValue_annotations);
+ PyObject *JoinedStr_annotations = PyDict_New();
+ if (!JoinedStr_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(JoinedStr_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(JoinedStr_annotations, "values", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(JoinedStr_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->JoinedStr_type, "_field_types",
+ JoinedStr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(JoinedStr_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->JoinedStr_type, "__annotations__",
+ JoinedStr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(JoinedStr_annotations);
+ return 0;
+ }
+ Py_DECREF(JoinedStr_annotations);
+ PyObject *Constant_annotations = PyDict_New();
+ if (!Constant_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyBaseObject_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Constant_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Constant_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Constant_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Constant_annotations, "kind", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Constant_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Constant_type, "_field_types",
+ Constant_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Constant_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Constant_type, "__annotations__",
+ Constant_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Constant_annotations);
+ return 0;
+ }
+ Py_DECREF(Constant_annotations);
+ PyObject *Attribute_annotations = PyDict_New();
+ if (!Attribute_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Attribute_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Attribute_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Attribute_annotations, "attr", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Attribute_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Attribute_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Attribute_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Attribute_type, "_field_types",
+ Attribute_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Attribute_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Attribute_type, "__annotations__",
+ Attribute_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Attribute_annotations);
+ return 0;
+ }
+ Py_DECREF(Attribute_annotations);
+ PyObject *Subscript_annotations = PyDict_New();
+ if (!Subscript_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Subscript_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Subscript_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Subscript_annotations, "slice", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Subscript_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Subscript_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Subscript_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Subscript_type, "_field_types",
+ Subscript_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Subscript_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Subscript_type, "__annotations__",
+ Subscript_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Subscript_annotations);
+ return 0;
+ }
+ Py_DECREF(Subscript_annotations);
+ PyObject *Starred_annotations = PyDict_New();
+ if (!Starred_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Starred_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Starred_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Starred_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Starred_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Starred_type, "_field_types",
+ Starred_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Starred_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Starred_type, "__annotations__",
+ Starred_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Starred_annotations);
+ return 0;
+ }
+ Py_DECREF(Starred_annotations);
+ PyObject *Name_annotations = PyDict_New();
+ if (!Name_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Name_annotations, "id", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Name_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Name_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Name_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Name_type, "_field_types",
+ Name_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Name_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Name_type, "__annotations__",
+ Name_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Name_annotations);
+ return 0;
+ }
+ Py_DECREF(Name_annotations);
+ PyObject *List_annotations = PyDict_New();
+ if (!List_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(List_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(List_annotations, "elts", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(List_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(List_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(List_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->List_type, "_field_types",
+ List_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(List_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->List_type, "__annotations__",
+ List_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(List_annotations);
+ return 0;
+ }
+ Py_DECREF(List_annotations);
+ PyObject *Tuple_annotations = PyDict_New();
+ if (!Tuple_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Tuple_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Tuple_annotations, "elts", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Tuple_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_context_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(Tuple_annotations, "ctx", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Tuple_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Tuple_type, "_field_types",
+ Tuple_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Tuple_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Tuple_type, "__annotations__",
+ Tuple_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Tuple_annotations);
+ return 0;
+ }
+ Py_DECREF(Tuple_annotations);
+ PyObject *Slice_annotations = PyDict_New();
+ if (!Slice_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Slice_annotations, "lower", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Slice_annotations, "upper", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(Slice_annotations, "step", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->Slice_type, "_field_types",
+ Slice_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Slice_type, "__annotations__",
+ Slice_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Slice_annotations);
+ return 0;
+ }
+ Py_DECREF(Slice_annotations);
+ PyObject *Load_annotations = PyDict_New();
+ if (!Load_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Load_type, "_field_types",
+ Load_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Load_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Load_type, "__annotations__",
+ Load_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Load_annotations);
+ return 0;
+ }
+ Py_DECREF(Load_annotations);
+ PyObject *Store_annotations = PyDict_New();
+ if (!Store_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Store_type, "_field_types",
+ Store_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Store_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Store_type, "__annotations__",
+ Store_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Store_annotations);
+ return 0;
+ }
+ Py_DECREF(Store_annotations);
+ PyObject *Del_annotations = PyDict_New();
+ if (!Del_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Del_type, "_field_types",
+ Del_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Del_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Del_type, "__annotations__",
+ Del_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Del_annotations);
+ return 0;
+ }
+ Py_DECREF(Del_annotations);
+ PyObject *And_annotations = PyDict_New();
+ if (!And_annotations) return 0;
+ cond = PyObject_SetAttrString(state->And_type, "_field_types",
+ And_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(And_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->And_type, "__annotations__",
+ And_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(And_annotations);
+ return 0;
+ }
+ Py_DECREF(And_annotations);
+ PyObject *Or_annotations = PyDict_New();
+ if (!Or_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Or_type, "_field_types",
+ Or_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Or_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Or_type, "__annotations__",
+ Or_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Or_annotations);
+ return 0;
+ }
+ Py_DECREF(Or_annotations);
+ PyObject *Add_annotations = PyDict_New();
+ if (!Add_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Add_type, "_field_types",
+ Add_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Add_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Add_type, "__annotations__",
+ Add_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Add_annotations);
+ return 0;
+ }
+ Py_DECREF(Add_annotations);
+ PyObject *Sub_annotations = PyDict_New();
+ if (!Sub_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Sub_type, "_field_types",
+ Sub_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Sub_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Sub_type, "__annotations__",
+ Sub_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Sub_annotations);
+ return 0;
+ }
+ Py_DECREF(Sub_annotations);
+ PyObject *Mult_annotations = PyDict_New();
+ if (!Mult_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Mult_type, "_field_types",
+ Mult_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Mult_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Mult_type, "__annotations__",
+ Mult_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Mult_annotations);
+ return 0;
+ }
+ Py_DECREF(Mult_annotations);
+ PyObject *MatMult_annotations = PyDict_New();
+ if (!MatMult_annotations) return 0;
+ cond = PyObject_SetAttrString(state->MatMult_type, "_field_types",
+ MatMult_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatMult_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatMult_type, "__annotations__",
+ MatMult_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatMult_annotations);
+ return 0;
+ }
+ Py_DECREF(MatMult_annotations);
+ PyObject *Div_annotations = PyDict_New();
+ if (!Div_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Div_type, "_field_types",
+ Div_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Div_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Div_type, "__annotations__",
+ Div_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Div_annotations);
+ return 0;
+ }
+ Py_DECREF(Div_annotations);
+ PyObject *Mod_annotations = PyDict_New();
+ if (!Mod_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Mod_type, "_field_types",
+ Mod_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Mod_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Mod_type, "__annotations__",
+ Mod_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Mod_annotations);
+ return 0;
+ }
+ Py_DECREF(Mod_annotations);
+ PyObject *Pow_annotations = PyDict_New();
+ if (!Pow_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Pow_type, "_field_types",
+ Pow_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Pow_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Pow_type, "__annotations__",
+ Pow_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Pow_annotations);
+ return 0;
+ }
+ Py_DECREF(Pow_annotations);
+ PyObject *LShift_annotations = PyDict_New();
+ if (!LShift_annotations) return 0;
+ cond = PyObject_SetAttrString(state->LShift_type, "_field_types",
+ LShift_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(LShift_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->LShift_type, "__annotations__",
+ LShift_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(LShift_annotations);
+ return 0;
+ }
+ Py_DECREF(LShift_annotations);
+ PyObject *RShift_annotations = PyDict_New();
+ if (!RShift_annotations) return 0;
+ cond = PyObject_SetAttrString(state->RShift_type, "_field_types",
+ RShift_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(RShift_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->RShift_type, "__annotations__",
+ RShift_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(RShift_annotations);
+ return 0;
+ }
+ Py_DECREF(RShift_annotations);
+ PyObject *BitOr_annotations = PyDict_New();
+ if (!BitOr_annotations) return 0;
+ cond = PyObject_SetAttrString(state->BitOr_type, "_field_types",
+ BitOr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitOr_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->BitOr_type, "__annotations__",
+ BitOr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitOr_annotations);
+ return 0;
+ }
+ Py_DECREF(BitOr_annotations);
+ PyObject *BitXor_annotations = PyDict_New();
+ if (!BitXor_annotations) return 0;
+ cond = PyObject_SetAttrString(state->BitXor_type, "_field_types",
+ BitXor_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitXor_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->BitXor_type, "__annotations__",
+ BitXor_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitXor_annotations);
+ return 0;
+ }
+ Py_DECREF(BitXor_annotations);
+ PyObject *BitAnd_annotations = PyDict_New();
+ if (!BitAnd_annotations) return 0;
+ cond = PyObject_SetAttrString(state->BitAnd_type, "_field_types",
+ BitAnd_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitAnd_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->BitAnd_type, "__annotations__",
+ BitAnd_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(BitAnd_annotations);
+ return 0;
+ }
+ Py_DECREF(BitAnd_annotations);
+ PyObject *FloorDiv_annotations = PyDict_New();
+ if (!FloorDiv_annotations) return 0;
+ cond = PyObject_SetAttrString(state->FloorDiv_type, "_field_types",
+ FloorDiv_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FloorDiv_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->FloorDiv_type, "__annotations__",
+ FloorDiv_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(FloorDiv_annotations);
+ return 0;
+ }
+ Py_DECREF(FloorDiv_annotations);
+ PyObject *Invert_annotations = PyDict_New();
+ if (!Invert_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Invert_type, "_field_types",
+ Invert_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Invert_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Invert_type, "__annotations__",
+ Invert_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Invert_annotations);
+ return 0;
+ }
+ Py_DECREF(Invert_annotations);
+ PyObject *Not_annotations = PyDict_New();
+ if (!Not_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Not_type, "_field_types",
+ Not_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Not_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Not_type, "__annotations__",
+ Not_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Not_annotations);
+ return 0;
+ }
+ Py_DECREF(Not_annotations);
+ PyObject *UAdd_annotations = PyDict_New();
+ if (!UAdd_annotations) return 0;
+ cond = PyObject_SetAttrString(state->UAdd_type, "_field_types",
+ UAdd_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(UAdd_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->UAdd_type, "__annotations__",
+ UAdd_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(UAdd_annotations);
+ return 0;
+ }
+ Py_DECREF(UAdd_annotations);
+ PyObject *USub_annotations = PyDict_New();
+ if (!USub_annotations) return 0;
+ cond = PyObject_SetAttrString(state->USub_type, "_field_types",
+ USub_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(USub_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->USub_type, "__annotations__",
+ USub_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(USub_annotations);
+ return 0;
+ }
+ Py_DECREF(USub_annotations);
+ PyObject *Eq_annotations = PyDict_New();
+ if (!Eq_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Eq_type, "_field_types",
+ Eq_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Eq_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Eq_type, "__annotations__",
+ Eq_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Eq_annotations);
+ return 0;
+ }
+ Py_DECREF(Eq_annotations);
+ PyObject *NotEq_annotations = PyDict_New();
+ if (!NotEq_annotations) return 0;
+ cond = PyObject_SetAttrString(state->NotEq_type, "_field_types",
+ NotEq_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NotEq_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->NotEq_type, "__annotations__",
+ NotEq_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NotEq_annotations);
+ return 0;
+ }
+ Py_DECREF(NotEq_annotations);
+ PyObject *Lt_annotations = PyDict_New();
+ if (!Lt_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Lt_type, "_field_types",
+ Lt_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Lt_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Lt_type, "__annotations__",
+ Lt_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Lt_annotations);
+ return 0;
+ }
+ Py_DECREF(Lt_annotations);
+ PyObject *LtE_annotations = PyDict_New();
+ if (!LtE_annotations) return 0;
+ cond = PyObject_SetAttrString(state->LtE_type, "_field_types",
+ LtE_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(LtE_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->LtE_type, "__annotations__",
+ LtE_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(LtE_annotations);
+ return 0;
+ }
+ Py_DECREF(LtE_annotations);
+ PyObject *Gt_annotations = PyDict_New();
+ if (!Gt_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Gt_type, "_field_types",
+ Gt_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Gt_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Gt_type, "__annotations__",
+ Gt_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Gt_annotations);
+ return 0;
+ }
+ Py_DECREF(Gt_annotations);
+ PyObject *GtE_annotations = PyDict_New();
+ if (!GtE_annotations) return 0;
+ cond = PyObject_SetAttrString(state->GtE_type, "_field_types",
+ GtE_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(GtE_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->GtE_type, "__annotations__",
+ GtE_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(GtE_annotations);
+ return 0;
+ }
+ Py_DECREF(GtE_annotations);
+ PyObject *Is_annotations = PyDict_New();
+ if (!Is_annotations) return 0;
+ cond = PyObject_SetAttrString(state->Is_type, "_field_types",
+ Is_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Is_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->Is_type, "__annotations__",
+ Is_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(Is_annotations);
+ return 0;
+ }
+ Py_DECREF(Is_annotations);
+ PyObject *IsNot_annotations = PyDict_New();
+ if (!IsNot_annotations) return 0;
+ cond = PyObject_SetAttrString(state->IsNot_type, "_field_types",
+ IsNot_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(IsNot_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->IsNot_type, "__annotations__",
+ IsNot_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(IsNot_annotations);
+ return 0;
+ }
+ Py_DECREF(IsNot_annotations);
+ PyObject *In_annotations = PyDict_New();
+ if (!In_annotations) return 0;
+ cond = PyObject_SetAttrString(state->In_type, "_field_types",
+ In_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(In_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->In_type, "__annotations__",
+ In_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(In_annotations);
+ return 0;
+ }
+ Py_DECREF(In_annotations);
+ PyObject *NotIn_annotations = PyDict_New();
+ if (!NotIn_annotations) return 0;
+ cond = PyObject_SetAttrString(state->NotIn_type, "_field_types",
+ NotIn_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NotIn_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->NotIn_type, "__annotations__",
+ NotIn_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(NotIn_annotations);
+ return 0;
+ }
+ Py_DECREF(NotIn_annotations);
+ PyObject *comprehension_annotations = PyDict_New();
+ if (!comprehension_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(comprehension_annotations, "target", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(comprehension_annotations, "iter", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(comprehension_annotations, "ifs", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyLong_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(comprehension_annotations, "is_async",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->comprehension_type, "_field_types",
+ comprehension_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->comprehension_type, "__annotations__",
+ comprehension_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(comprehension_annotations);
+ return 0;
+ }
+ Py_DECREF(comprehension_annotations);
+ PyObject *ExceptHandler_annotations = PyDict_New();
+ if (!ExceptHandler_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ExceptHandler_annotations, "type", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ExceptHandler_annotations, "name", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(ExceptHandler_annotations, "body", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->ExceptHandler_type, "_field_types",
+ ExceptHandler_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->ExceptHandler_type, "__annotations__",
+ ExceptHandler_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ExceptHandler_annotations);
+ return 0;
+ }
+ Py_DECREF(ExceptHandler_annotations);
+ PyObject *arguments_annotations = PyDict_New();
+ if (!arguments_annotations) return 0;
+ {
+ PyObject *type = state->arg_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "posonlyargs", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arg_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "args", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arg_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "vararg", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arg_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "kwonlyargs", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "kw_defaults", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->arg_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "kwarg", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arguments_annotations, "defaults", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->arguments_type, "_field_types",
+ arguments_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->arguments_type, "__annotations__",
+ arguments_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(arguments_annotations);
+ return 0;
+ }
+ Py_DECREF(arguments_annotations);
+ PyObject *arg_annotations = PyDict_New();
+ if (!arg_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(arg_annotations, "arg", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arg_annotations, "annotation", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(arg_annotations, "type_comment", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->arg_type, "_field_types",
+ arg_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->arg_type, "__annotations__",
+ arg_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(arg_annotations);
+ return 0;
+ }
+ Py_DECREF(arg_annotations);
+ PyObject *keyword_annotations = PyDict_New();
+ if (!keyword_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(keyword_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(keyword_annotations, "arg", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(keyword_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(keyword_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(keyword_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->keyword_type, "_field_types",
+ keyword_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(keyword_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->keyword_type, "__annotations__",
+ keyword_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(keyword_annotations);
+ return 0;
+ }
+ Py_DECREF(keyword_annotations);
+ PyObject *alias_annotations = PyDict_New();
+ if (!alias_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(alias_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(alias_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(alias_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(alias_annotations, "asname", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(alias_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->alias_type, "_field_types",
+ alias_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(alias_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->alias_type, "__annotations__",
+ alias_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(alias_annotations);
+ return 0;
+ }
+ Py_DECREF(alias_annotations);
+ PyObject *withitem_annotations = PyDict_New();
+ if (!withitem_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(withitem_annotations, "context_expr", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(withitem_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(withitem_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(withitem_annotations, "optional_vars",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(withitem_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->withitem_type, "_field_types",
+ withitem_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(withitem_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->withitem_type, "__annotations__",
+ withitem_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(withitem_annotations);
+ return 0;
+ }
+ Py_DECREF(withitem_annotations);
+ PyObject *match_case_annotations = PyDict_New();
+ if (!match_case_annotations) return 0;
+ {
+ PyObject *type = state->pattern_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(match_case_annotations, "pattern", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(match_case_annotations, "guard", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->stmt_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(match_case_annotations, "body", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->match_case_type, "_field_types",
+ match_case_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->match_case_type, "__annotations__",
+ match_case_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(match_case_annotations);
+ return 0;
+ }
+ Py_DECREF(match_case_annotations);
+ PyObject *MatchValue_annotations = PyDict_New();
+ if (!MatchValue_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(MatchValue_annotations, "value", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchValue_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchValue_type, "_field_types",
+ MatchValue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchValue_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchValue_type, "__annotations__",
+ MatchValue_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchValue_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchValue_annotations);
+ PyObject *MatchSingleton_annotations = PyDict_New();
+ if (!MatchSingleton_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyBaseObject_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(MatchSingleton_annotations, "value", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchSingleton_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchSingleton_type, "_field_types",
+ MatchSingleton_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchSingleton_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchSingleton_type,
+ "__annotations__",
+ MatchSingleton_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchSingleton_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchSingleton_annotations);
+ PyObject *MatchSequence_annotations = PyDict_New();
+ if (!MatchSequence_annotations) return 0;
+ {
+ PyObject *type = state->pattern_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchSequence_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchSequence_annotations, "patterns",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchSequence_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchSequence_type, "_field_types",
+ MatchSequence_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchSequence_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchSequence_type, "__annotations__",
+ MatchSequence_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchSequence_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchSequence_annotations);
+ PyObject *MatchMapping_annotations = PyDict_New();
+ if (!MatchMapping_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchMapping_annotations, "keys", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->pattern_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchMapping_annotations, "patterns", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchMapping_annotations, "rest", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchMapping_type, "_field_types",
+ MatchMapping_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchMapping_type, "__annotations__",
+ MatchMapping_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchMapping_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchMapping_annotations);
+ PyObject *MatchClass_annotations = PyDict_New();
+ if (!MatchClass_annotations) return 0;
+ {
+ PyObject *type = state->expr_type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(MatchClass_annotations, "cls", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->pattern_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchClass_annotations, "patterns", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchClass_annotations, "kwd_attrs", type)
+ == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->pattern_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchClass_annotations, "kwd_patterns",
+ type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchClass_type, "_field_types",
+ MatchClass_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchClass_type, "__annotations__",
+ MatchClass_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchClass_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchClass_annotations);
+ PyObject *MatchStar_annotations = PyDict_New();
+ if (!MatchStar_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchStar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchStar_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchStar_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchStar_type, "_field_types",
+ MatchStar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchStar_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchStar_type, "__annotations__",
+ MatchStar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchStar_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchStar_annotations);
+ PyObject *MatchAs_annotations = PyDict_New();
+ if (!MatchAs_annotations) return 0;
+ {
+ PyObject *type = state->pattern_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchAs_annotations, "pattern", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchAs_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchAs_type, "_field_types",
+ MatchAs_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchAs_type, "__annotations__",
+ MatchAs_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchAs_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchAs_annotations);
+ PyObject *MatchOr_annotations = PyDict_New();
+ if (!MatchOr_annotations) return 0;
+ {
+ PyObject *type = state->pattern_type;
+ type = Py_GenericAlias((PyObject *)&PyList_Type, type);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(MatchOr_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(MatchOr_annotations, "patterns", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(MatchOr_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->MatchOr_type, "_field_types",
+ MatchOr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchOr_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->MatchOr_type, "__annotations__",
+ MatchOr_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(MatchOr_annotations);
+ return 0;
+ }
+ Py_DECREF(MatchOr_annotations);
+ PyObject *TypeIgnore_annotations = PyDict_New();
+ if (!TypeIgnore_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyLong_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeIgnore_annotations, "lineno", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeIgnore_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeIgnore_annotations, "tag", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeIgnore_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->TypeIgnore_type, "_field_types",
+ TypeIgnore_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeIgnore_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->TypeIgnore_type, "__annotations__",
+ TypeIgnore_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeIgnore_annotations);
+ return 0;
+ }
+ Py_DECREF(TypeIgnore_annotations);
+ PyObject *TypeVar_annotations = PyDict_New();
+ if (!TypeVar_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeVar_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeVar_annotations);
+ return 0;
+ }
+ }
+ {
+ PyObject *type = state->expr_type;
+ type = _Py_union_type_or(type, Py_None);
+ cond = type != NULL;
+ if (!cond) {
+ Py_DECREF(TypeVar_annotations);
+ return 0;
+ }
+ cond = PyDict_SetItemString(TypeVar_annotations, "bound", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeVar_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->TypeVar_type, "_field_types",
+ TypeVar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeVar_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->TypeVar_type, "__annotations__",
+ TypeVar_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeVar_annotations);
+ return 0;
+ }
+ Py_DECREF(TypeVar_annotations);
+ PyObject *ParamSpec_annotations = PyDict_New();
+ if (!ParamSpec_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(ParamSpec_annotations, "name", type) == 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(ParamSpec_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->ParamSpec_type, "_field_types",
+ ParamSpec_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ParamSpec_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->ParamSpec_type, "__annotations__",
+ ParamSpec_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(ParamSpec_annotations);
+ return 0;
+ }
+ Py_DECREF(ParamSpec_annotations);
+ PyObject *TypeVarTuple_annotations = PyDict_New();
+ if (!TypeVarTuple_annotations) return 0;
+ {
+ PyObject *type = (PyObject *)&PyUnicode_Type;
+ Py_INCREF(type);
+ cond = PyDict_SetItemString(TypeVarTuple_annotations, "name", type) ==
+ 0;
+ Py_DECREF(type);
+ if (!cond) {
+ Py_DECREF(TypeVarTuple_annotations);
+ return 0;
+ }
+ }
+ cond = PyObject_SetAttrString(state->TypeVarTuple_type, "_field_types",
+ TypeVarTuple_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeVarTuple_annotations);
+ return 0;
+ }
+ cond = PyObject_SetAttrString(state->TypeVarTuple_type, "__annotations__",
+ TypeVarTuple_annotations) == 0;
+ if (!cond) {
+ Py_DECREF(TypeVarTuple_annotations);
+ return 0;
+ }
+ Py_DECREF(TypeVarTuple_annotations);
+
+ return 1;
+}
+
+
typedef struct {
PyObject_HEAD
@@ -860,7 +5026,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
Py_ssize_t i, numfields = 0;
int res = -1;
- PyObject *key, *value, *fields;
+ PyObject *key, *value, *fields, *remaining_fields = NULL;
if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
goto cleanup;
}
@@ -869,6 +5035,13 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
if (numfields == -1) {
goto cleanup;
}
+ remaining_fields = PySet_New(fields);
+ }
+ else {
+ remaining_fields = PySet_New(NULL);
+ }
+ if (remaining_fields == NULL) {
+ goto cleanup;
}
res = 0; /* if no error occurs, this stays 0 to the end */
@@ -888,6 +5061,11 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
goto cleanup;
}
res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
+ if (PySet_Discard(remaining_fields, name) < 0) {
+ res = -1;
+ Py_DECREF(name);
+ goto cleanup;
+ }
Py_DECREF(name);
if (res < 0) {
goto cleanup;
@@ -900,13 +5078,14 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
if (contains == -1) {
res = -1;
goto cleanup;
- } else if (contains == 1) {
- Py_ssize_t p = PySequence_Index(fields, key);
+ }
+ else if (contains == 1) {
+ int p = PySet_Discard(remaining_fields, key);
if (p == -1) {
res = -1;
goto cleanup;
}
- if (p < PyTuple_GET_SIZE(args)) {
+ if (p == 0) {
PyErr_Format(PyExc_TypeError,
"%.400s got multiple values for argument '%U'",
Py_TYPE(self)->tp_name, key);
@@ -914,15 +5093,91 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
goto cleanup;
}
}
+ else if (
+ PyUnicode_CompareWithASCIIString(key, "lineno") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "col_offset") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "end_lineno") != 0 &&
+ PyUnicode_CompareWithASCIIString(key, "end_col_offset") != 0
+ ) {
+ if (PyErr_WarnFormat(
+ PyExc_DeprecationWarning, 1,
+ "%.400s.__init__ got an unexpected keyword argument '%U'. "
+ "Support for arbitrary keyword arguments is deprecated "
+ "and will be removed in Python 3.15.",
+ Py_TYPE(self)->tp_name, key
+ ) < 0) {
+ res = -1;
+ goto cleanup;
+ }
+ }
res = PyObject_SetAttr(self, key, value);
if (res < 0) {
goto cleanup;
}
}
}
+ Py_ssize_t size = PySet_Size(remaining_fields);
+ PyObject *field_types = NULL, *remaining_list = NULL;
+ if (size > 0) {
+ if (!PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), &_Py_ID(_field_types),
+ &field_types)) {
+ res = -1;
+ goto cleanup;
+ }
+ remaining_list = PySequence_List(remaining_fields);
+ if (!remaining_list) {
+ goto set_remaining_cleanup;
+ }
+ for (Py_ssize_t i = 0; i < size; i++) {
+ PyObject *name = PyList_GET_ITEM(remaining_list, i);
+ PyObject *type = PyDict_GetItemWithError(field_types, name);
+ if (!type) {
+ if (!PyErr_Occurred()) {
+ PyErr_SetObject(PyExc_KeyError, name);
+ }
+ goto set_remaining_cleanup;
+ }
+ if (_PyUnion_Check(type)) {
+ // optional field
+ // do nothing, we'll have set a None default on the class
+ }
+ else if (Py_IS_TYPE(type, &Py_GenericAliasType)) {
+ // list field
+ PyObject *empty = PyList_New(0);
+ if (!empty) {
+ goto set_remaining_cleanup;
+ }
+ res = PyObject_SetAttr(self, name, empty);
+ Py_DECREF(empty);
+ if (res < 0) {
+ goto set_remaining_cleanup;
+ }
+ }
+ else {
+ // simple field (e.g., identifier)
+ if (PyErr_WarnFormat(
+ PyExc_DeprecationWarning, 1,
+ "%.400s.__init__ missing 1 required positional argument: '%U'. "
+ "This will become an error in Python 3.15.",
+ Py_TYPE(self)->tp_name, name
+ ) < 0) {
+ res = -1;
+ goto cleanup;
+ }
+ }
+ }
+ Py_DECREF(remaining_list);
+ Py_DECREF(field_types);
+ }
cleanup:
Py_XDECREF(fields);
+ Py_XDECREF(remaining_fields);
return res;
+ set_remaining_cleanup:
+ Py_XDECREF(remaining_list);
+ Py_XDECREF(field_types);
+ res = -1;
+ goto cleanup;
}
/* Pickling support */
@@ -934,14 +5189,75 @@ ast_type_reduce(PyObject *self, PyObject *unused)
return NULL;
}
- PyObject *dict;
+ PyObject *dict = NULL, *fields = NULL, *remaining_fields = NULL,
+ *remaining_dict = NULL, *positional_args = NULL;
if (PyObject_GetOptionalAttr(self, state->__dict__, &dict) < 0) {
return NULL;
}
+ PyObject *result = NULL;
if (dict) {
- return Py_BuildValue("O()N", Py_TYPE(self), dict);
+ // Serialize the fields as positional args if possible, because if we
+ // serialize them as a dict, during unpickling they are set only *after*
+ // the object is constructed, which will now trigger a DeprecationWarning
+ // if the AST type has required fields.
+ if (PyObject_GetOptionalAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
+ goto cleanup;
+ }
+ if (fields) {
+ Py_ssize_t numfields = PySequence_Size(fields);
+ if (numfields == -1) {
+ Py_DECREF(dict);
+ goto cleanup;
+ }
+ remaining_dict = PyDict_Copy(dict);
+ Py_DECREF(dict);
+ if (!remaining_dict) {
+ goto cleanup;
+ }
+ positional_args = PyList_New(0);
+ if (!positional_args) {
+ goto cleanup;
+ }
+ for (Py_ssize_t i = 0; i < numfields; i++) {
+ PyObject *name = PySequence_GetItem(fields, i);
+ if (!name) {
+ goto cleanup;
+ }
+ PyObject *value = PyDict_GetItemWithError(remaining_dict, name);
+ if (!value) {
+ if (PyErr_Occurred()) {
+ goto cleanup;
+ }
+ break;
+ }
+ if (PyList_Append(positional_args, value) < 0) {
+ goto cleanup;
+ }
+ if (PyDict_DelItem(remaining_dict, name) < 0) {
+ goto cleanup;
+ }
+ Py_DECREF(name);
+ }
+ PyObject *args_tuple = PyList_AsTuple(positional_args);
+ if (!args_tuple) {
+ goto cleanup;
+ }
+ result = Py_BuildValue("ONO", Py_TYPE(self), args_tuple,
+ remaining_dict);
+ }
+ else {
+ result = Py_BuildValue("O()N", Py_TYPE(self), dict);
+ }
+ }
+ else {
+ result = Py_BuildValue("O()", Py_TYPE(self));
}
- return Py_BuildValue("O()", Py_TYPE(self));
+cleanup:
+ Py_XDECREF(fields);
+ Py_XDECREF(remaining_fields);
+ Py_XDECREF(remaining_dict);
+ Py_XDECREF(positional_args);
+ return result;
}
static PyMemberDef ast_type_members[] = {
@@ -1939,6 +6255,9 @@ init_types(struct ast_state *state)
"TypeVarTuple(identifier name)");
if (!state->TypeVarTuple_type) return -1;
+ if (!add_ast_annotations(state)) {
+ return -1;
+ }
return 0;
}