@@ -375,16 +375,16 @@ class OverloadedFuncDef(FuncBase, SymbolNode, Statement):
375375 Overloaded variants must be consecutive in the source file.
376376 """
377377
378- items = None # type: List[Decorator ]
379- impl = None # type: Optional[FuncDef ]
378+ items = None # type: List[OverloadPart ]
379+ impl = None # type: Optional[OverloadPart ]
380380
381- def __init__ (self , items : List ['Decorator' ], impl : Optional [ Union [ 'Decorator' , 'FuncDef' ]] = None ) -> None :
381+ def __init__ (self , items : List ['OverloadPart' ] ) -> None :
382382 self .items = items
383- self .impl = impl
383+ self .impl = None
384384 self .set_line (items [0 ].line )
385385
386386 def name (self ) -> str :
387- return self .items [0 ].func . name ()
387+ return self .items [0 ].name ()
388388
389389 def accept (self , visitor : StatementVisitor [T ]) -> T :
390390 return visitor .visit_overloaded_func_def (self )
@@ -401,10 +401,11 @@ def serialize(self) -> JsonDict:
401401 @classmethod
402402 def deserialize (cls , data : JsonDict ) -> 'OverloadedFuncDef' :
403403 assert data ['.class' ] == 'OverloadedFuncDef'
404- impl = None # type: Optional[FuncDef]
404+ res = OverloadedFuncDef ([
405+ cast (OverloadPart , OverloadPart .deserialize (d ))
406+ for d in data ['items' ]])
405407 if data .get ('impl' ) is not None :
406- impl = FuncDef .deserialize (data ['impl' ])
407- res = OverloadedFuncDef ([Decorator .deserialize (d ) for d in data ['items' ]], impl )
408+ res .impl = cast (OverloadPart , OverloadPart .deserialize (data ['impl' ]))
408409 if data .get ('type' ) is not None :
409410 res .type = mypy .types .Type .deserialize (data ['type' ])
410411 res ._fullname = data ['fullname' ]
@@ -511,7 +512,16 @@ def is_dynamic(self) -> bool:
511512 return self .type is None
512513
513514
514- class FuncDef (FuncItem , SymbolNode , Statement ):
515+ class OverloadPart (SymbolNode , Statement ):
516+ """Interface class for statments that can be part of an OverloadedFuncDef"""
517+
518+ is_overload = False
519+
520+ @abstractmethod
521+ def get_body (self ) -> Optional ['Block' ]: pass
522+
523+
524+ class FuncDef (FuncItem , OverloadPart , Statement ):
515525 """Function definition.
516526
517527 This is a non-lambda function defined using 'def'.
@@ -541,6 +551,9 @@ def name(self) -> str:
541551 def accept (self , visitor : StatementVisitor [T ]) -> T :
542552 return visitor .visit_func_def (self )
543553
554+ def get_body (self ) -> Optional ['Block' ]:
555+ return self .body
556+
544557 def serialize (self ) -> JsonDict :
545558 # We're deliberating omitting arguments and storing only arg_names and
546559 # arg_kinds for space-saving reasons (arguments is not used in later
@@ -579,7 +592,7 @@ def deserialize(cls, data: JsonDict) -> 'FuncDef':
579592 return ret
580593
581594
582- class Decorator (SymbolNode , Statement ):
595+ class Decorator (OverloadPart , Statement ):
583596 """A decorated function.
584597
585598 A single Decorator object can include any number of function decorators.
@@ -588,6 +601,7 @@ class Decorator(SymbolNode, Statement):
588601 func = None # type: FuncDef # Decorated function
589602 decorators = None # type: List[Expression] # Decorators, at least one # XXX Not true
590603 var = None # type: Var # Represents the decorated function obj
604+ type = None # type: mypy.types.Type
591605 is_overload = False
592606
593607 def __init__ (self , func : FuncDef , decorators : List [Expression ],
@@ -600,6 +614,9 @@ def __init__(self, func: FuncDef, decorators: List[Expression],
600614 def name (self ) -> str :
601615 return self .func .name ()
602616
617+ def get_body (self ) -> Optional ['Block' ]:
618+ return self .func .body
619+
603620 def fullname (self ) -> str :
604621 return self .func .fullname ()
605622
0 commit comments