Code using postponed evaluation of annotations (PEP 563) is rejected with a SyntaxError
See original GitHub issueNuitka chokes on files that make use of annotations that are only valid with PEP 563, which was added in Python 3.7. Among other changes, it allows type annotations for methods in a class to use the name of the class in which they were defined. For example, the following is not valid without PEP 563 due to Foo
not being defined at the point it is used in the type definition:
class Foo:
def make_foo() -> Foo:
return Foo()
This is valid in Python 3.7+ when from __future__ import annotations
is used, and will become the default in Python 4.
- Nuitka version, full Python version and Platform (Windows, OSX, Linux …)
(ins)awang@sid:/tmp/nuitka$ apt show python3.7
Package: python3.7
Version: 3.7.1-1
<snip>
(ins)awang@sid:/tmp/nuitka$ python3.7 -m nuitka --version
0.6.1rc7
Python: 3.7.0+ (default, Aug 31 2018, 23:21:37)
Executable: /home/awang/.cache/pypoetry/virtualenvs/test-py3.7/bin/python3.7
OS: Linux
Arch: x86_64
- How did you install Nuitka and Python (pip, anaconda, deb, rpm, from source, what is a virtualenv …), this is very important usually.
Python was installed using apt
and Nuitka was installed through poetry
with the following pyproject.toml
:
[tool.poetry]
name = "test"
version = "0.1.0"
description = ""
authors = [""]
[tool.poetry.dependencies]
python = "^3.7"
[tool.poetry.dev-dependencies]
nuitka = {git = "https://github.com/Nuitka/Nuitka", branch = "develop"}
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
- If possible please supply a Short, Self Contained, Correct, Example that demonstrates the issue i.e a small piece of code which reproduces the issue and can be run with out any other (or as few as possible) external dependencies.
The following file demonstrates the issue:
from __future__ import annotations
class Foo:
def make_foo() -> Foo:
return Foo()
(ins)awang@sid:/tmp/nuitka$ python3.7 test.py
(ins)awang@sid:/tmp/nuitka$ echo $?
0
(ins)awang@sid:/tmp/nuitka$ python3.7 -m nuitka test.py
File "test.py", line 1
from __future__ import annotations
^
SyntaxError: future feature annotations is not defined
Nuitka is very syntax compatible with standard Python. It is currently running
with Python version '3.7', you might want to specify more clearly with the use
of the precise Python interpreter binary and '-m nuitka', e.g. use this
'python2.7 -m nuitka' option, if that's not the one the program expects.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
PEP 563 – Postponed Evaluation of Annotations
An annotation is no longer evaluated at the time of definition and, more importantly, in the same scope where it was defined. Consequently, ......
Read more >Python News: What's New From April 2021
PEP 649 proposes a deferred evaluation of annotations instead of PEP 563's postponed evaluation. In short, PEP 649 defers the evaluation of type...
Read more >Python 3.10: What's New - TestDriven.io
This article looks at the new features in Python 3.10 and how they can be ... postponed evaluation of annotations proposes to save...
Read more >Annotation issues at runtime - mypy 0.991 documentation
Use of from __future__ import annotations (PEP 563) (this behaviour may ... way to tell mypy something without the code being evaluated at...
Read more >Leading items [LWN.net]
Forward references in annotations and a few other problems led to PEP 563 (" Postponed Evaluation of Annotations "), which sought to delay...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is indeed going to change for 3.8, my workaround is in develop and will be in the next stable release, therefore closing.
So the issue is https://bugs.python.org/issue35143
Lets hope I was stupid, and it has just escaped my attention, or they add it for 3.8 at least.