[Python-porting] Function annotation syntax for 2.7/3.5 compatibility and pasteurize
Brett Cannon
brett at python.org
Fri Dec 23 11:17:31 EST 2016
More information about the Python-porting mailing list
Fri Dec 23 11:17:31 EST 2016
- Previous message (by thread): [Python-porting] Function annotation syntax for 2.7/3.5 compatibility and pasteurize
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 23 Dec 2016 at 05:50 Michael Rans via Python-porting < python-porting at python.org> wrote: > Hi, > > Which is the correct way of doing function annotations that work in 2.7 > and 3.5? > > https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code > or > http://python-future.org/func_annotations.html#func-annotations > ? > The best ways is either the type comment you mention above or https://www.python.org/dev/peps/pep-0484/#stub-files. The suggestion from Future will keep the information in the same spot that Python 3 code expects it to be, it won't work with tools like mypy. So if you're doing it to access the info at runtime then the Future suggestion works, but if you're doing it for type checking you want the other ways (and you can obviously combine approaches if you want everything :) ). -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-porting/attachments/20161223/f395d111/attachment.html>
- Previous message (by thread): [Python-porting] Function annotation syntax for 2.7/3.5 compatibility and pasteurize
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-porting mailing list