Skip to content

future doesn't support python3 functions annotations #2

Open

Description

@matclab

I just tried future on a python3 program and it fails on python3 functions annotations (http://www.python.org/dev/peps/pep-3107/) :

    def _parse(self, filename: str, dir='.') -> list:
                             ^
SyntaxError: invalid syntax

I'm not sure if there is a way to fix this.

Activity

  1. edschofield commented on Oct 21, 2013

    @edschofield
    Contributor

    Hi @matclab,

    Thanks for reporting this. Yes, this is a known limitation. Any Python 3-only syntax will fail to run on Python 2; importing future cannot help with this because Python won't even attempt to run code that generates a SyntaxError.

    The futurize script could potentially convert function annotations into the following syntax, which is compatible with both Py2 and Py3 (using your example)::

    def _parse(self, filename, dir='.'):
        ...
    _parse.__annotations__ = {'filename': str, 'return': list}
    

    Would this meet your use-case? I have filed this as a feature request in issue #3.

  2. matclab commented on Nov 2, 2013

    @matclab
    Author

    I may give a try, but I can not see why it won't work for my use case…
    Thanks for having considered it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions