Merge pull request #2409 from tausbn/python-typing-forward-reference-fp

Python: Support forward references inside return type annotations.
This commit is contained in:
Rasmus Wriedt Larsen
2019-11-22 11:18:04 +01:00
committed by GitHub
2 changed files with 25 additions and 2 deletions

View File

@@ -64,9 +64,11 @@ private string doctest_in_scope(Scope scope) {
pragma[noinline]
private string typehint_annotation_in_file(File file) {
exists(StrConst annotation |
annotation = any(Arguments a).getAnAnnotation()
annotation = any(Arguments a).getAnAnnotation().getASubExpression*()
or
annotation = any(AnnAssign a).getAnnotation()
annotation = any(AnnAssign a).getAnnotation().getASubExpression*()
or
annotation = any(FunctionExpr f).getReturns().getASubExpression*()
|
annotation.pointsTo(Value::forString(result)) and
file = annotation.getLocation().getFile()

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