Pablo Galindo Salgado <pablog...@gmail.com> added the comment:
If you want to add a test, you could check the dis output for this example: def make_func(x): def f(x : not (x is x), /): ... In this case the compiler emits: 3 0 LOAD_GLOBAL 0 (x) 2 LOAD_GLOBAL 0 (x) 4 COMPARE_OP 8 (is) 6 UNARY_NOT 8 LOAD_CONST 1 (('x',)) 10 BUILD_CONST_KEY_MAP 1 12 LOAD_CONST 2 (<code object f at 0x7f3754f71040, file "/home/pablogsal/github/python/master/lel.py", line 3>) 14 LOAD_CONST 3 ('code.<locals>.f') 16 MAKE_FUNCTION 4 (annotations) 18 STORE_FAST 0 (f) while for def make_func(x): def f(x : not (x is x)): . emits more efficient code (using 'not is' instead of is and UNARY_NOT: 4 20 LOAD_GLOBAL 0 (x) 22 LOAD_GLOBAL 0 (x) 24 COMPARE_OP 9 (is not) 26 LOAD_CONST 1 (('x',)) 28 BUILD_CONST_KEY_MAP 1 30 LOAD_CONST 4 (<code object g at 0x7f3754f135f0, file "/home/pablogsal/github/python/master/lel.py", line 4>) 32 LOAD_CONST 5 ('code.<locals>.g') 34 MAKE_FUNCTION 4 (annotations) 36 STORE_FAST 1 (g) 38 LOAD_CONST 0 (None) 40 RETURN_VALUE Adding the missing line makes them do the same. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39216> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com