2015-05-29 14:53:24 +08:00
|
|
|
"""
|
|
|
|
The typedtree module exports the PythonParser AST enriched with
|
|
|
|
typing information.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from pythonparser import ast
|
|
|
|
|
|
|
|
class commontyped(ast.commonloc):
|
|
|
|
"""A mixin for typed AST nodes."""
|
|
|
|
|
2015-06-05 17:04:27 +08:00
|
|
|
_types = ("type",)
|
2015-05-29 14:53:24 +08:00
|
|
|
|
|
|
|
def _reprfields(self):
|
|
|
|
return self._fields + self._locs + self._types
|
|
|
|
|
|
|
|
class scoped(object):
|
|
|
|
"""
|
|
|
|
:ivar typing_env: (dict with string keys and :class:`.types.Type` values)
|
|
|
|
map of variable names to variable types
|
|
|
|
:ivar globals_in_scope: (set of string keys)
|
2015-07-18 13:13:49 +08:00
|
|
|
set of variables resolved as globals
|
2015-05-29 14:53:24 +08:00
|
|
|
"""
|
|
|
|
|
2015-06-14 17:07:13 +08:00
|
|
|
# Typed versions of untyped nodes
|
2015-06-04 19:12:41 +08:00
|
|
|
class argT(ast.arg, commontyped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
|
|
|
|
2015-08-15 21:45:16 +08:00
|
|
|
class ClassDefT(ast.ClassDef):
|
|
|
|
_types = ("constructor_type",)
|
2015-05-29 14:53:24 +08:00
|
|
|
class FunctionDefT(ast.FunctionDef, scoped):
|
2015-06-15 16:30:50 +08:00
|
|
|
_types = ("signature_type",)
|
2016-03-27 04:01:51 +08:00
|
|
|
class QuotedFunctionDefT(FunctionDefT):
|
|
|
|
pass
|
2015-06-13 14:28:40 +08:00
|
|
|
class ModuleT(ast.Module, scoped):
|
|
|
|
pass
|
2015-05-29 14:53:24 +08:00
|
|
|
|
2015-07-03 02:28:26 +08:00
|
|
|
class ExceptHandlerT(ast.ExceptHandler):
|
2015-08-15 21:45:16 +08:00
|
|
|
_fields = ("filter", "name", "body") # rename ast.ExceptHandler.type to filter
|
2015-06-29 05:31:06 +08:00
|
|
|
_types = ("name_type",)
|
|
|
|
|
2015-12-16 15:33:15 +08:00
|
|
|
class ForT(ast.For):
|
|
|
|
"""
|
|
|
|
:ivar trip_count: (:class:`iodelay.Expr`)
|
|
|
|
:ivar trip_interval: (:class:`iodelay.Expr`)
|
|
|
|
"""
|
|
|
|
|
2016-01-05 00:11:03 +08:00
|
|
|
class withitemT(ast.withitem):
|
|
|
|
_types = ("enter_type", "exit_type")
|
|
|
|
|
2015-07-16 19:53:24 +08:00
|
|
|
class SliceT(ast.Slice, commontyped):
|
|
|
|
pass
|
|
|
|
|
2015-06-04 19:12:41 +08:00
|
|
|
class AttributeT(ast.Attribute, commontyped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
2015-06-04 19:12:41 +08:00
|
|
|
class BinOpT(ast.BinOp, commontyped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
2015-06-04 19:12:41 +08:00
|
|
|
class BoolOpT(ast.BoolOp, commontyped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
2015-06-04 19:12:41 +08:00
|
|
|
class CallT(ast.Call, commontyped):
|
2015-11-17 10:16:43 +08:00
|
|
|
"""
|
|
|
|
:ivar iodelay: (:class:`iodelay.Expr`)
|
2015-12-25 15:02:33 +08:00
|
|
|
:ivar arg_exprs: (dict of str to :class:`iodelay.Expr`)
|
2015-11-17 10:16:43 +08:00
|
|
|
"""
|
2015-06-04 19:12:41 +08:00
|
|
|
class CompareT(ast.Compare, commontyped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
2015-06-04 19:12:41 +08:00
|
|
|
class DictT(ast.Dict, commontyped):
|
|
|
|
pass
|
|
|
|
class DictCompT(ast.DictComp, commontyped, scoped):
|
|
|
|
pass
|
|
|
|
class EllipsisT(ast.Ellipsis, commontyped):
|
|
|
|
pass
|
|
|
|
class GeneratorExpT(ast.GeneratorExp, commontyped, scoped):
|
|
|
|
pass
|
|
|
|
class IfExpT(ast.IfExp, commontyped):
|
|
|
|
pass
|
|
|
|
class LambdaT(ast.Lambda, commontyped, scoped):
|
|
|
|
pass
|
|
|
|
class ListT(ast.List, commontyped):
|
|
|
|
pass
|
|
|
|
class ListCompT(ast.ListComp, commontyped, scoped):
|
2015-05-29 14:53:24 +08:00
|
|
|
pass
|
|
|
|
class NameT(ast.Name, commontyped):
|
|
|
|
pass
|
|
|
|
class NameConstantT(ast.NameConstant, commontyped):
|
|
|
|
pass
|
2015-06-04 19:12:41 +08:00
|
|
|
class NumT(ast.Num, commontyped):
|
|
|
|
pass
|
|
|
|
class SetT(ast.Set, commontyped):
|
|
|
|
pass
|
|
|
|
class SetCompT(ast.SetComp, commontyped, scoped):
|
|
|
|
pass
|
|
|
|
class StrT(ast.Str, commontyped):
|
|
|
|
pass
|
|
|
|
class StarredT(ast.Starred, commontyped):
|
|
|
|
pass
|
|
|
|
class SubscriptT(ast.Subscript, commontyped):
|
|
|
|
pass
|
|
|
|
class TupleT(ast.Tuple, commontyped):
|
|
|
|
pass
|
|
|
|
class UnaryOpT(ast.UnaryOp, commontyped):
|
|
|
|
pass
|
|
|
|
class YieldT(ast.Yield, commontyped):
|
|
|
|
pass
|
|
|
|
class YieldFromT(ast.YieldFrom, commontyped):
|
|
|
|
pass
|
2015-06-14 17:07:13 +08:00
|
|
|
|
|
|
|
# Novel typed nodes
|
|
|
|
class CoerceT(ast.expr, commontyped):
|
2015-07-16 19:55:23 +08:00
|
|
|
_fields = ('value',) # other_value deliberately not in _fields
|
2015-08-07 16:44:49 +08:00
|
|
|
class QuoteT(ast.expr, commontyped):
|
|
|
|
_fields = ('value',)
|