Towards fixing annotated decorator functions...

and annotate functions
This commit is contained in:
rocky
2017-04-11 05:10:38 -04:00
parent 41343c27b7
commit 6acec471e3
6 changed files with 9 additions and 4 deletions

View File

@@ -17,3 +17,9 @@ def div(a: dict(type=float, help='the dividend'),
) -> dict(type=float, help='the result of dividing a by b'): ) -> dict(type=float, help='the result of dividing a by b'):
"""Divide a by b""" """Divide a by b"""
return a / b return a / b
class SupportsInt(_Protocol):
@abstractmethod
def __int__(self) -> int:
pass

View File

@@ -275,12 +275,15 @@ class Python3Parser(PythonParser):
stmt ::= funcdef_annotate stmt ::= funcdef_annotate
funcdef_annotate ::= mkfunc_annotate designator funcdef_annotate ::= mkfunc_annotate designator
mkfuncdeco0 ::= mkfunc_annotate
# This has the annotation value. # This has the annotation value.
# LOAD_NAME is used in an annotation type like # LOAD_NAME is used in an annotation type like
# int, float, str # int, float, str
annotate_arg ::= LOAD_NAME annotate_arg ::= LOAD_NAME
# LOAD_CONST is used in an annotation string # LOAD_CONST is used in an annotation string
annotate_arg ::= LOAD_CONST annotate_arg ::= LOAD_CONST
annotate_arg ::= LOAD_GLOBAL
# This stores the tuple of parameter names # This stores the tuple of parameter names
# that have been annotated # that have been annotated
@@ -709,9 +712,6 @@ class Python3Parser(PythonParser):
('pos_arg ' * args_pos, opname)) ('pos_arg ' * args_pos, opname))
self.add_unique_rule(rule, opname, token.attr, customize) self.add_unique_rule(rule, opname, token.attr, customize)
if opname.startswith('MAKE_FUNCTION_A'): if opname.startswith('MAKE_FUNCTION_A'):
# rule = ('mkfunc2 ::= %s%sEXTENDED_ARG %s' %
# ('pos_arg ' * (args_pos), 'kwargs ' * (annotate_args-1), opname))
self.add_unique_rule(rule, opname, token.attr, customize)
if self.version >= 3.3: if self.version >= 3.3:
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' % rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
(('pos_arg ' * (args_pos)), (('pos_arg ' * (args_pos)),

View File

@@ -1788,7 +1788,6 @@ class SourceWalker(GenericASTTraversal, object):
# lowest down the stack # lowest down the stack
na = (v & 0xff) # positional parameters na = (v & 0xff) # positional parameters
if self.version == 3.5 and na == 0: if self.version == 3.5 and na == 0:
print("XXX", k)
if p2[2]: p2 = (2, -2, ', ') if p2[2]: p2 = (2, -2, ', ')
entry = (str, 0, p2, 1, -2) entry = (str, 0, p2, 1, -2)
else: else: