@@ -804,15 +804,28 @@ def diagnose(valid_forms):
804
804
elif builtins .is_builtin (typ , "class list" ):
805
805
valid_forms = lambda : [
806
806
valid_form ("list() -> list(elt='a)" ),
807
- # TODO: add this form when adding iterators
808
- # valid_form("list(x) -> list(elt='a)")
807
+ valid_form ("list(x:'a) -> list(elt='b) where 'a is iterable" )
809
808
]
810
809
811
810
self ._unify (node .type , builtins .TList (),
812
811
node .loc , None )
813
812
814
813
if len (node .args ) == 0 and len (node .keywords ) == 0 :
815
814
pass # []
815
+ elif len (node .args ) == 1 and len (node .keywords ) == 0 :
816
+ arg , = node .args
817
+
818
+ if builtins .is_iterable (arg .type ):
819
+ pass
820
+ else :
821
+ note = diagnostic .Diagnostic ("note" ,
822
+ "this expression has type {type}" ,
823
+ {"type" : types .TypePrinter ().name (arg .type )},
824
+ arg .loc )
825
+ diag = diagnostic .Diagnostic ("error" ,
826
+ "the argument of list() must be of an iterable type" , {},
827
+ node .func .loc , notes = [note ])
828
+ self .engine .process (diag )
816
829
else :
817
830
diagnose (valid_forms ())
818
831
elif builtins .is_builtin (typ , "function range" ):
@@ -854,7 +867,7 @@ def diagnose(valid_forms):
854
867
if len (node .args ) == 1 and len (node .keywords ) == 0 :
855
868
arg , = node .args
856
869
857
- if builtins .is_list ( arg . type ) or builtins . is_range (arg .type ):
870
+ if builtins .is_iterable (arg .type ):
858
871
pass
859
872
else :
860
873
note = diagnostic .Diagnostic ("note" ,
0 commit comments