-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
featuretopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations
Description
(Not sure if it should be here or in typing)
Consider this function:
def f():
return "hello"
def g(x):
if x: return A(1)
else: return A(2)
f
obviously (without any deep analysis) returns str
, and g
returns A. Why not use this information? This pattern is very common, and taking advantage of it can help in precise checking and remove clutter (for example -> Union[Tuple[int, int, str], Tuple[int, str, bool]]
).
I propose treating calls to functions whose return expressions consists solely of literals and constructor calls as if they were declared with the returned type (join or union of the return types).
akdor1154, maxfischer2781, nyanpasu64, kaste, sbdchd and 32 moresterliakov and ml-taehoon-choimehmetozsoy-synnada
Metadata
Metadata
Assignees
Labels
featuretopic-inferenceWhen to infer types or require explicit annotationsWhen to infer types or require explicit annotations