无法从__future__导入注释 [英] Can't import annotations from __future__

查看:1650
本文介绍了无法从__future__导入注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行语句时

from __future__ import annotations

我收到以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.5/py_compile.py", line 125, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap_external>", line 735, in source_to_code
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "./prog.py", line 1
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.5/py_compile.py", line 129, in compile
    raise py_exc
py_compile.PyCompileError:   File "./prog.py", line 1
    from __future__ import annotations
                                     ^
SyntaxError: future feature annotations is not defined

此错误可能是什么原因?

What could be the cause of this error?

推荐答案

查看您的错误回溯,看来您正在使用python 3.5.是这样吗?

Looking at your error traceback, it looks like you are using python 3.5. Is that the case?

如果是这样,则会发生错误,因为根据

If so, then the error happens because according to PEP-563 the import of __future__ annotations is available starting with Python 3.7.

我没有发现任何暗示它会被反向移植到以前的版本,但是我可能会错过它.

I did not find any hints that this will be backported to previous versions, but I might have missed that.

这篇关于无法从__future__导入注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆