[Python-ideas] Add an optional type file for Type Annotation

Steven D'Aprano steve at pearwood.info
Wed Jun 27 01:08:31 EDT 2018

On Tue, Jun 26, 2018 at 08:59:22PM -0700, 李者璈 wrote:

> I'm inspired by TypeScript.
> TypeScript allows people to add **.d.ts* *to annotate ECMAScript's type. So 
> this can expand the TypeScript's scenes to be used。

I'm sorry, I do not understand what you mean by this. Unless you mean 
stub files? Stub files are already supported.


> So I think can we add an optional mechanism to allow people add the extra 
> file to annotate the existing code.
> Type Annotation can be used after Python 3.5. but many lib/framework has to 
> be compatible for the Python 3.0-3.4, they can't use annotation.

Function annotations work in Python 3.0 onwards.

Using comments for annotations work for any version of Python:

x = []                # type: List[Employee]

This is also discussed in the PEP.


More information about the Python-ideas mailing list