This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Type Annotation of nested function with positional only arguments triggers SystemError
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Anthony Sottile, pablogsal
Priority: normal Keywords: patch

Created on 2020-01-05 00:30 by Anthony Sottile, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17826 merged Anthony Sottile, 2020-01-05 01:30
PR 17827 merged miss-islington, 2020-01-05 01:58
Messages (4)
msg359312 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-01-05 00:30
def f():
    def g(arg: int, /):


$ python3.9
Traceback (most recent call last):
  File "/home/asottile/workspace/", line 5, in <module>
  File "/home/asottile/workspace/", line 2, in f
    def g(arg: int, /):
SystemError: no locals when loading 'int'

Originally from this StackOverflow post:
msg359313 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-01-05 00:35
Looks as though annotations are using `LOAD_NAME` when they should probably use `LOAD_GLOBAL`?

$ diff -u <(python3.9 -m dis | sed 's/0x[a-f0-9]*/0xdeadbeef/g;s/t2\.py/FILENAME/g') <(python3.9 -m dis | sed 's/0x[a-f0-9]*/0xdeadbeef/g;s/t3\.py/FILENAME/g')
--- /dev/fd/63	2020-01-04 16:34:27.372004436 -0800
+++ /dev/fd/62	2020-01-04 16:34:27.372004436 -0800
@@ -10,7 +10,7 @@
              16 RETURN_VALUE
 Disassembly of <code object f at 0xdeadbeef, file "FILENAME", line 1>:
-  2           0 LOAD_NAME                0 (int)
+  2           0 LOAD_GLOBAL              0 (int)
               2 LOAD_CONST               1 (('arg',))
               4 BUILD_CONST_KEY_MAP      1
               6 LOAD_CONST               2 (<code object g at 0xdeadbeef, file "FILENAME", line 2>)
``` is the same as but without positional-only arguments
msg359315 - (view) Author: Anthony Sottile (Anthony Sottile) * Date: 2020-01-05 01:14
this triggers an assertion when run with debug enabled:

$ gdb ./python 
GNU gdb (Ubuntu 8.1-0ubuntu3.2)
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./python...done.
warning: File "/home/asottile/workspace/cpython/" auto-loading has been declined by your `auto-load safe-path' set to "$debugdir:$datadir/auto-load".
To enable execution of this file add
	add-auto-load-safe-path /home/asottile/workspace/cpython/
line to your configuration file "/home/asottile/.gdbinit".
To completely disable this security protection add
	set auto-load safe-path /
line to your configuration file "/home/asottile/.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual.  E.g., run from the shell:
	info "(gdb)Auto-loading safe path"
(gdb) run
Starting program: /home/asottile/workspace/cpython/python
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/".
python: Python/compile.c:3545: compiler_nameop: Assertion `scope || PyUnicode_READ_CHAR(name, 0) == '_'' failed.

Program received signal SIGABRT, Aborted.
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#1  0x00007ffff7060801 in __GI_abort () at abort.c:79
#2  0x00007ffff705039a in __assert_fail_base (
    fmt=0x7ffff71d77d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x555555815190 "scope || PyUnicode_READ_CHAR(name, 0) == '_'", file=file@entry=0x555555814233 "Python/compile.c", 
    function=function@entry=0x555555814180 <__PRETTY_FUNCTION__.17589> "compiler_nameop") at assert.c:92
#3  0x00007ffff7050412 in __GI___assert_fail (
    assertion=assertion@entry=0x555555815190 "scope || PyUnicode_READ_CHAR(name, 0) == '_'", file=file@entry=0x555555814233 "Python/compile.c", 
    function=function@entry=0x555555814180 <__PRETTY_FUNCTION__.17589> "compiler_nameop") at assert.c:101
#4  0x000055555568e946 in compiler_nameop (c=0x7fffffffdb40, 
    name=<optimized out>, ctx=Load) at Python/compile.c:3545
#5  0x000055555569020e in compiler_visit_expr1 (c=c@entry=0x7fffffffdb40, 
    e=0x555555b739d0) at Python/compile.c:5027
#6  0x000055555569027f in compiler_visit_expr (c=0x7fffffffdb40, 
    e=<optimized out>) at Python/compile.c:5052
#7  0x0000555555693570 in compiler_visit_argannotation (
    c=c@entry=0x7fffffffdb40, id=0x7ffff7f95d60, annotation=<optimized out>, 
    names=names@entry=0x7ffff66217d0) at Python/compile.c:2045
#8  0x000055555569363e in compiler_visit_argannotations (
    c=c@entry=0x7fffffffdb40, args=0x555555b739c0, 
    names=names@entry=0x7ffff66217d0) at Python/compile.c:2066
#9  0x00005555556936b2 in compiler_visit_annotations (
    c=c@entry=0x7fffffffdb40, args=args@entry=0x555555b73a28, 
    returns=returns@entry=0x0) at Python/compile.c:2094
#10 0x00005555556939fc in compiler_function (c=0x7fffffffdb40, 
    s=0x555555b73ab8, is_async=is_async@entry=0) at Python/compile.c:2214
#11 0x0000555555693dad in compiler_visit_stmt (c=c@entry=0x7fffffffdb40, 
    s=0x555555b73ab8) at Python/compile.c:3332
---Type <return> to continue, or q <return> to quit---
#12 0x0000555555693b8f in compiler_function (c=0x7fffffffdb40, 
    s=<optimized out>, is_async=is_async@entry=0) at Python/compile.c:2238
#13 0x0000555555693dad in compiler_visit_stmt (c=c@entry=0x7fffffffdb40, 
    s=0x555555b73b00) at Python/compile.c:3332
#14 0x0000555555694022 in compiler_body (c=c@entry=0x7fffffffdb40, 
    stmts=0x555555b73960) at Python/compile.c:1816
#15 0x0000555555694754 in compiler_mod (c=c@entry=0x7fffffffdb40, 
    mod=mod@entry=0x555555b73c00) at Python/compile.c:1836
#16 0x000055555569682b in PyAST_CompileObject (mod=mod@entry=0x555555b73c00, 
    filename=filename@entry=0x7ffff662a7b0, flags=flags@entry=0x7fffffffddc0, 
    optimize=optimize@entry=-1, arena=arena@entry=0x7ffff7e69640)
    at Python/compile.c:364
#17 0x00005555556c20cc in run_mod (mod=mod@entry=0x555555b73c00, 
    globals=globals@entry=0x7ffff7ecf3b0, locals=locals@entry=0x7ffff7ecf3b0, 
    flags=flags@entry=0x7fffffffddc0, arena=arena@entry=0x7ffff7e69640)
    at Python/pythonrun.c:1138
#18 0x00005555556c530c in PyRun_FileExFlags (fp=fp@entry=0x555555b6d000, 
    filename_str=filename_str@entry=0x7ffff7ecf720 "/home/asottile/workspace/cpython/", start=start@entry=257, globals=globals@entry=0x7ffff7ecf3b0, 
    locals=locals@entry=0x7ffff7ecf3b0, closeit=closeit@entry=1, 
    flags=0x7fffffffddc0) at Python/pythonrun.c:1063
#19 0x00005555556c56e6 in PyRun_SimpleFileExFlags (fp=fp@entry=0x555555b6d000, 
    filename=<optimized out>, 
    filename@entry=0x7ffff7ecf720 "/home/asottile/workspace/cpython/", 
    closeit=closeit@entry=1, flags=flags@entry=0x7fffffffddc0)
    at Python/pythonrun.c:428
#20 0x00005555556c58e9 in PyRun_AnyFileExFlags (fp=fp@entry=0x555555b6d000, 
    filename=0x7ffff7ecf720 "/home/asottile/workspace/cpython/", 
    closeit=closeit@entry=1, flags=flags@entry=0x7fffffffddc0)
    at Python/pythonrun.c:86
#21 0x00005555555aceca in pymain_run_file (config=config@entry=0x555555b2f190, 
    cf=cf@entry=0x7fffffffddc0) at Modules/main.c:369
#22 0x00005555555ad698 in pymain_run_python (
    exitcode=exitcode@entry=0x7fffffffddf4) at Modules/main.c:553
#23 0x00005555555ad703 in Py_RunMain () at Modules/main.c:632
#24 0x00005555555ad77d in pymain_main (args=args@entry=0x7fffffffde50)
    at Modules/main.c:662
#25 0x00005555555ad843 in Py_BytesMain (argc=<optimized out>, 
    argv=<optimized out>) at Modules/main.c:686
---Type <return> to continue, or q <return> to quit---
#26 0x00005555555ac053 in main (argc=<optimized out>, argv=<optimized out>)
    at ./Programs/python.c:16
msg359319 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2020-01-05 02:15
Thanks, Anthony, for the quick fix and the investigation! :)
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83396
2020-01-05 02:15:30pablogsalsetstatus: open -> closed

nosy: + pablogsal
messages: + msg359319

resolution: fixed
stage: patch review -> resolved
2020-01-05 01:58:49miss-islingtonsetpull_requests: + pull_request17255
2020-01-05 01:30:30Anthony Sottilesetkeywords: + patch
stage: patch review
pull_requests: + pull_request17254
2020-01-05 01:14:43Anthony Sottilesetmessages: + msg359315
2020-01-05 00:35:43Anthony Sottilesetmessages: + msg359313
2020-01-05 00:30:24Anthony Sottilecreate