Python: Support forward references inside return type annotations.

Should fix #2407.

Also allows for the string containing the forward reference to appear inside a
subexpression of the type annotation.
This commit is contained in:
Taus Brock-Nannestad
2019-11-21 15:37:32 +01:00
parent 77c869f528
commit 033524ce63
2 changed files with 25 additions and 2 deletions

View File

@@ -90,3 +90,24 @@ def func(x: 'Optional[only_used_in_parameter_annotation]'):
import only_used_in_annotated_assignment
var : 'Optional[only_used_in_annotated_assignment]' = 5
import used_in_return_type
def look_at_my_return_type() -> 'Optional[used_in_return_type]':
pass
# Uses inside strings appearing as subexpressions of an annotation:
import subexpression_parameter_annotation
def bar(x: Optional['subexpression_parameter_annotation']):
pass
import subexpression_assignment_annotation
var3 : Optional['subexpression_assignment_annotation'] = None
import subexpression_return_type
def baz() -> Optional['subexpression_return_type']:
pass