News for hackers. Stuff that matters.
Re:Static types in Python by ddorian43 on Thursday October 13, 2016 @05:33PM (#12704223)
I think you have to import that.
Re:Static types in Python by singularity2001 on Thursday October 13, 2016 @05:34PM (#12704234)
import List??

At least this works: def sum_and_stringify(nums: list) -> str:

Re:Static types in Python by ddfisher on Thursday October 13, 2016 @05:40PM (#12704280)
Yeah, you need to write `from typing import List` to get the generic List class that you can parameterize with an item type. As you pointed out, you can use the builtin lowercase-l list without importing anything, but that doesn't allow you to specify the item type.
Re:Static types in Python by ddorian43 on Thursday October 13, 2016 @05:45PM (#12704327)
No. Try: from typing import List, TYPE_CHECKING

How I found it: quick google search for "mypy validate list"

Re:Static types in Python by dcre on Thursday October 13, 2016 @05:36PM (#12704249)
The built-in constructor is `list`, not `List`.
Re:Static types in Python by singularity2001 on Thursday October 13, 2016 @05:39PM (#12704270)
Thanks for all the help guys! by the way I took the example from the mypy page

    def sum_and_stringify(nums: list[int]) -> str:  
TypeError: 'type' object is not subscriptable

so either just list or List[int] with import, got it.

A classical case of 'critical line missing from example code' (as perfectioned by Bjarne Stroustrup back when)