There is some test code:
some_type = int
def func0():
def func1(arg: some_type, /):
pass
func0()
And I get the following error:
Traceback (most recent call last):
...
SystemError: no locals when loading 'some_type'
However the code below works as expected:
some_type = int
def func0():
def func1(arg: some_type):
pass
func0()
And this one is also valid:
some_type = int
exec('''
def func1(arg: some_type, /):
pass
''')
I know that annotations will no longer be evaluated at definition time in future versions; also it is possible to activate such behaviour in 3.7+ versions. Something like
from __future__ import annotations
some_type = int
def func0():
def func1(arg: some_type, /):
pass
func0()
has no problems as well. However, the question is about the current strange behaviour at function definition time. some_type
is in no way a local variable of func0
, though python thinks so. One more fine version:
def func0():
some_type = int
def func1(arg: some_type, /):
pass
func0()
I've read PEP 570 but not found anything about annotations declarations there.
My python version:
sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)