When running the statement
from __future__ import annotations
I get the following error:
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?
__future__ module is a built-in module in Python that is used to inherit new features that will be available in the new Python versions.. This module includes all the latest functions which were not present in the previous version in Python. And we can use this by importing the __future__ module.
It's an enhancement to the existing annotations feature which was initially introduced in python 3.0 and redefined as type hints in python 3.5, that's why your code works under python 3.8. It will become the default in Python 3.10*.
The main function of from __future__ import print_function is to bring the print function from Python 3 into Python 2.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With