(.venv) C:\clones\cpython>C:\clones\cpython\.venv\Scripts\python.exe c:/clones/cpython/field_types.py
3.13.5 (tags/v3.13.5:6cb20a2, Jun 11 2025, 16:15:46) [MSC v.1943 64 bit (AMD64)]
astClass._fields
AST ()
mod ()
stmt ()
expr ()
expr_context ()
boolop ()
operator ()
unaryop ()
cmpop ()
comprehension ('target', 'iter', 'ifs', 'is_async')
excepthandler ()
arguments ('posonlyargs', 'args', 'vararg', 'kwonlyargs', 'kw_defaults', 'kwarg', 'defaults')
arg ('arg', 'annotation', 'type_comment')
keyword ('arg', 'value')
alias ('name', 'asname')
withitem ('context_expr', 'optional_vars')
match_case ('pattern', 'guard', 'body')
pattern ()
type_ignore ()
type_param ()
slice ()
Num ('n',)
Str ('s',)
Bytes ('s',)
NameConstant ('value', 'kind')
Ellipsis ()
Module ('body', 'type_ignores')
Interactive ('body',)
Expression ('body',)
FunctionType ('argtypes', 'returns')
Suite ()
FunctionDef ('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params')
AsyncFunctionDef ('name', 'args', 'body', 'decorator_list', 'returns', 'type_comment', 'type_params')
ClassDef ('name', 'bases', 'keywords', 'body', 'decorator_list', 'type_params')
Return ('value',)
Delete ('targets',)
Assign ('targets', 'value', 'type_comment')
TypeAlias ('name', 'type_params', 'value')
AugAssign ('target', 'op', 'value')
AnnAssign ('target', 'annotation', 'value', 'simple')
For ('target', 'iter', 'body', 'orelse', 'type_comment')
AsyncFor ('target', 'iter', 'body', 'orelse', 'type_comment')
While ('test', 'body', 'orelse')
If ('test', 'body', 'orelse')
With ('items', 'body', 'type_comment')
AsyncWith ('items', 'body', 'type_comment')
Match ('subject', 'cases')
Raise ('exc', 'cause')
Try ('body', 'handlers', 'orelse', 'finalbody')
TryStar ('body', 'handlers', 'orelse', 'finalbody')
Assert ('test', 'msg')
Import ('names',)
ImportFrom ('module', 'names', 'level')
Global ('names',)
Nonlocal ('names',)
Expr ('value',)
Pass ()
Break ()
Continue ()
BoolOp ('op', 'values')
NamedExpr ('target', 'value')
BinOp ('left', 'op', 'right')
UnaryOp ('op', 'operand')
Lambda ('args', 'body')
IfExp ('test', 'body', 'orelse')
Dict ('keys', 'values')
Set ('elts',)
ListComp ('elt', 'generators')
SetComp ('elt', 'generators')
DictComp ('key', 'value', 'generators')
GeneratorExp ('elt', 'generators')
Await ('value',)
Yield ('value',)
YieldFrom ('value',)
Compare ('left', 'ops', 'comparators')
Call ('func', 'args', 'keywords')
FormattedValue ('value', 'conversion', 'format_spec')
JoinedStr ('values',)
Constant ('value', 'kind')
Attribute ('value', 'attr', 'ctx')
Subscript ('value', 'slice', 'ctx')
Starred ('value', 'ctx')
Name ('id', 'ctx')
List ('elts', 'ctx')
Tuple ('elts', 'ctx')
Slice ('lower', 'upper', 'step')
Load ()
Store ()
Del ()
AugLoad ()
AugStore ()
Param ()
And ()
Or ()
Add ()
Sub ()
Mult ()
MatMult ()
Div ()
Mod ()
Pow ()
LShift ()
RShift ()
BitOr ()
BitXor ()
BitAnd ()
FloorDiv ()
Invert ()
Not ()
UAdd ()
USub ()
Eq ()
NotEq ()
Lt ()
LtE ()
Gt ()
GtE ()
Is ()
IsNot ()
In ()
NotIn ()
ExceptHandler ('type', 'name', 'body')
MatchValue ('value',)
MatchSingleton ('value',)
MatchSequence ('patterns',)
MatchMapping ('keys', 'patterns', 'rest')
MatchClass ('cls', 'patterns', 'kwd_attrs', 'kwd_patterns')
MatchStar ('name',)
MatchAs ('pattern', 'name')
MatchOr ('patterns',)
TypeIgnore ('lineno', 'tag')
TypeVar ('name', 'bound', 'default_value')
ParamSpec ('name', 'default_value')
TypeVarTuple ('name', 'default_value')
Index ()
ExtSlice ()
countExceptions = 0
astClass._field_types
AttributeError: AST
AttributeError: mod
AttributeError: stmt
AttributeError: expr
AttributeError: expr_context
AttributeError: boolop
AttributeError: operator
AttributeError: unaryop
AttributeError: cmpop
comprehension {'target': <class 'ast.expr'>, 'iter': <class 'ast.expr'>, 'ifs': list[ast.expr], 'is_async': <class 'int'>}
AttributeError: excepthandler
arguments {'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]}
arg {'arg': <class 'str'>, 'annotation': ast.expr | None, 'type_comment': str | None}
keyword {'arg': str | None, 'value': <class 'ast.expr'>}
alias {'name': <class 'str'>, 'asname': str | None}
withitem {'context_expr': <class 'ast.expr'>, 'optional_vars': ast.expr | None}
match_case {'pattern': <class 'ast.pattern'>, 'guard': ast.expr | None, 'body': list[ast.stmt]}
AttributeError: pattern
AttributeError: type_ignore
AttributeError: type_param
AttributeError: slice
Num {'value': <class 'object'>, 'kind': str | None}
Str {'value': <class 'object'>, 'kind': str | None}
Bytes {'value': <class 'object'>, 'kind': str | None}
NameConstant {'value': <class 'object'>, 'kind': str | None}
Ellipsis {'value': <class 'object'>, 'kind': str | None}
Module {'body': list[ast.stmt], 'type_ignores': list[ast.type_ignore]}
Interactive {'body': list[ast.stmt]}
Expression {'body': <class 'ast.expr'>}
FunctionType {'argtypes': list[ast.expr], 'returns': <class 'ast.expr'>}
AttributeError: Suite
FunctionDef {'name': <class 'str'>, 'args': <class 'ast.arguments'>, 'body': list[ast.stmt], 'decorator_list': list[ast.expr], 'returns': ast.expr | None, 'type_comment': str | None, 'type_params': list[ast.type_param]}
AsyncFunctionDef {'name': <class 'str'>, 'args': <class 'ast.arguments'>, 'body': list[ast.stmt], 'decorator_list': list[ast.expr], 'returns': ast.expr | None, 'type_comment': str | None, 'type_params': list[ast.type_param]}
ClassDef {'name': <class 'str'>, 'bases': list[ast.expr], 'keywords': list[ast.keyword], 'body': list[ast.stmt], 'decorator_list': list[ast.expr], 'type_params': list[ast.type_param]}
Return {'value': ast.expr | None}
Delete {'targets': list[ast.expr]}
Assign {'targets': list[ast.expr], 'value': <class 'ast.expr'>, 'type_comment': str | None}
TypeAlias {'name': <class 'ast.expr'>, 'type_params': list[ast.type_param], 'value': <class 'ast.expr'>}
AugAssign {'target': <class 'ast.expr'>, 'op': <class 'ast.operator'>, 'value': <class 'ast.expr'>}
AnnAssign {'target': <class 'ast.expr'>, 'annotation': <class 'ast.expr'>, 'value': ast.expr | None, 'simple': <class 'int'>}
For {'target': <class 'ast.expr'>, 'iter': <class 'ast.expr'>, 'body': list[ast.stmt], 'orelse': list[ast.stmt], 'type_comment': str | None}
AsyncFor {'target': <class 'ast.expr'>, 'iter': <class 'ast.expr'>, 'body': list[ast.stmt], 'orelse': list[ast.stmt], 'type_comment': str | None}
While {'test': <class 'ast.expr'>, 'body': list[ast.stmt], 'orelse': list[ast.stmt]}
If {'test': <class 'ast.expr'>, 'body': list[ast.stmt], 'orelse': list[ast.stmt]}
With {'items': list[ast.withitem], 'body': list[ast.stmt], 'type_comment': str | None}
AsyncWith {'items': list[ast.withitem], 'body': list[ast.stmt], 'type_comment': str | None}
Match {'subject': <class 'ast.expr'>, 'cases': list[ast.match_case]}
Raise {'exc': ast.expr | None, 'cause': ast.expr | None}
Try {'body': list[ast.stmt], 'handlers': list[ast.excepthandler], 'orelse': list[ast.stmt], 'finalbody': list[ast.stmt]}
TryStar {'body': list[ast.stmt], 'handlers': list[ast.excepthandler], 'orelse': list[ast.stmt], 'finalbody': list[ast.stmt]}
Assert {'test': <class 'ast.expr'>, 'msg': ast.expr | None}
Import {'names': list[ast.alias]}
ImportFrom {'module': str | None, 'names': list[ast.alias], 'level': int | None}
Global {'names': list[str]}
Nonlocal {'names': list[str]}
Expr {'value': <class 'ast.expr'>}
Pass {}
Break {}
Continue {}
BoolOp {'op': <class 'ast.boolop'>, 'values': list[ast.expr]}
NamedExpr {'target': <class 'ast.expr'>, 'value': <class 'ast.expr'>}
BinOp {'left': <class 'ast.expr'>, 'op': <class 'ast.operator'>, 'right': <class 'ast.expr'>}
UnaryOp {'op': <class 'ast.unaryop'>, 'operand': <class 'ast.expr'>}
Lambda {'args': <class 'ast.arguments'>, 'body': <class 'ast.expr'>}
IfExp {'test': <class 'ast.expr'>, 'body': <class 'ast.expr'>, 'orelse': <class 'ast.expr'>}
Dict {'keys': list[ast.expr], 'values': list[ast.expr]}
Set {'elts': list[ast.expr]}
ListComp {'elt': <class 'ast.expr'>, 'generators': list[ast.comprehension]}
SetComp {'elt': <class 'ast.expr'>, 'generators': list[ast.comprehension]}
DictComp {'key': <class 'ast.expr'>, 'value': <class 'ast.expr'>, 'generators': list[ast.comprehension]}
GeneratorExp {'elt': <class 'ast.expr'>, 'generators': list[ast.comprehension]}
Await {'value': <class 'ast.expr'>}
Yield {'value': ast.expr | None}
YieldFrom {'value': <class 'ast.expr'>}
Compare {'left': <class 'ast.expr'>, 'ops': list[ast.cmpop], 'comparators': list[ast.expr]}
Call {'func': <class 'ast.expr'>, 'args': list[ast.expr], 'keywords': list[ast.keyword]}
FormattedValue {'value': <class 'ast.expr'>, 'conversion': <class 'int'>, 'format_spec': ast.expr | None}
JoinedStr {'values': list[ast.expr]}
Constant {'value': <class 'object'>, 'kind': str | None}
Attribute {'value': <class 'ast.expr'>, 'attr': <class 'str'>, 'ctx': <class 'ast.expr_context'>}
Subscript {'value': <class 'ast.expr'>, 'slice': <class 'ast.expr'>, 'ctx': <class 'ast.expr_context'>}
Starred {'value': <class 'ast.expr'>, 'ctx': <class 'ast.expr_context'>}
Name {'id': <class 'str'>, 'ctx': <class 'ast.expr_context'>}
List {'elts': list[ast.expr], 'ctx': <class 'ast.expr_context'>}
Tuple {'elts': list[ast.expr], 'ctx': <class 'ast.expr_context'>}
Slice {'lower': ast.expr | None, 'upper': ast.expr | None, 'step': ast.expr | None}
Load {}
Store {}
Del {}
AttributeError: AugLoad
AttributeError: AugStore
AttributeError: Param
And {}
Or {}
Add {}
Sub {}
Mult {}
MatMult {}
Div {}
Mod {}
Pow {}
LShift {}
RShift {}
BitOr {}
BitXor {}
BitAnd {}
FloorDiv {}
Invert {}
Not {}
UAdd {}
USub {}
Eq {}
NotEq {}
Lt {}
LtE {}
Gt {}
GtE {}
Is {}
IsNot {}
In {}
NotIn {}
ExceptHandler {'type': ast.expr | None, 'name': str | None, 'body': list[ast.stmt]}
MatchValue {'value': <class 'ast.expr'>}
MatchSingleton {'value': <class 'object'>}
MatchSequence {'patterns': list[ast.pattern]}
MatchMapping {'keys': list[ast.expr], 'patterns': list[ast.pattern], 'rest': str | None}
MatchClass {'cls': <class 'ast.expr'>, 'patterns': list[ast.pattern], 'kwd_attrs': list[str], 'kwd_patterns': list[ast.pattern]}
MatchStar {'name': str | None}
MatchAs {'pattern': ast.pattern | None, 'name': str | None}
MatchOr {'patterns': list[ast.pattern]}
TypeIgnore {'lineno': <class 'int'>, 'tag': <class 'str'>}
TypeVar {'name': <class 'str'>, 'bound': ast.expr | None, 'default_value': ast.expr | None}
ParamSpec {'name': <class 'str'>, 'default_value': ast.expr | None}
TypeVarTuple {'name': <class 'str'>, 'default_value': ast.expr | None}
AttributeError: Index
AttributeError: ExtSlice
countExceptions = 20
Bug report
Bug description:
_fieldand_field_typesbehave differentlyAccessing the
_field_typesattribute of anast.ASTsubclass will cause an exception if the class has no_fields, but accessing the_fieldsattribute never causes an exception.Example:
ast.mod_fieldand_field_typesfor allast.ASTsubclassesDetails
No errors after code changes
After adding logic to "Parser/asdl_c.py" to treat
_field_typessimilar to_fields, the exceptions were replaced with empty dictionaries.Summary
_field_typesfor allast.ASTsubclassesDetails
Check for errors on branches
Not applicable to 3.9, 3.10, 3.11, 3.12.
Branch 3.13
Details
Branch 3.14
Details
Branch main
Details
Python code used to generate the above tests
Details
CPython versions tested on:
3.13, 3.14, CPython main branch
Operating systems tested on:
Windows
Linked PRs