Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-43693 Get rid of CO_NOFREE -- it's unused #26839

Merged
merged 4 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Doc/library/inspect.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1450,10 +1450,6 @@ the following flags:
The flag is set when the code object is a generator function, i.e.
a generator object is returned when the code object is executed.

.. data:: CO_NOFREE

The flag is set if there are no free or cell variables.

.. data:: CO_COROUTINE

The flag is set when the code object is a coroutine function.
Expand Down
6 changes: 0 additions & 6 deletions Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ struct PyCodeObject {
#define CO_VARKEYWORDS 0x0008
#define CO_NESTED 0x0010
#define CO_GENERATOR 0x0020
/* The CO_NOFREE flag is set if there are no free or cell variables.
This information is redundant, but it allows a single flag test
to determine whether there is any extra work to be done when the
call frame it setup.
*/
#define CO_NOFREE 0x0040

/* The CO_COROUTINE flag is set for coroutine functions (defined with
``async def`` keywords) */
Expand Down
14 changes: 5 additions & 9 deletions Lib/test/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
cellvars: ()
freevars: ()
nlocals: 5
flags: 67
flags: 3
consts: ('None',)

>>> def attrs(obj):
Expand All @@ -67,7 +67,7 @@
cellvars: ()
freevars: ()
nlocals: 1
flags: 67
flags: 3
consts: ('None',)

>>> def optimize_away():
Expand All @@ -86,7 +86,7 @@
cellvars: ()
freevars: ()
nlocals: 0
flags: 67
flags: 3
consts: ("'doc string'", 'None')

>>> def keywordonly_args(a,b,*,k1):
Expand All @@ -103,7 +103,7 @@
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
flags: 3
consts: ('None',)

>>> def posonly_args(a,b,/,c):
Expand All @@ -120,7 +120,7 @@
cellvars: ()
freevars: ()
nlocals: 3
flags: 67
flags: 3
consts: ('None',)

"""
Expand Down Expand Up @@ -199,10 +199,6 @@ class List(list):
class_ref = function.__closure__[0].cell_contents
self.assertIs(class_ref, List)

# Ensure the code correctly indicates it accesses a free variable
self.assertFalse(function.__code__.co_flags & inspect.CO_NOFREE,
hex(function.__code__.co_flags))

# Ensure the zero-arg super() call in the injected method works
obj = List([1, 2, 3])
self.assertEqual(obj[0], "Foreign getitem: 1")
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ def get_disassembly(self, func, lasti=-1, wrapper=True, **kwargs):
Kw-only arguments: 0
Number of locals: 1
Stack size: 3
Flags: OPTIMIZED, NEWLOCALS, NOFREE
Flags: OPTIMIZED, NEWLOCALS
Constants:
{code_info_consts}
Names:
Expand Down Expand Up @@ -800,7 +800,7 @@ def f(c=c):
Kw-only arguments: 0
Number of locals: 0
Stack size: 2
Flags: NOFREE
Flags: 0x0
Constants:
0: 1
Names:
Expand All @@ -814,7 +814,7 @@ def f(c=c):
Kw-only arguments: 0
Number of locals: 0
Stack size: 2
Flags: NOFREE
Flags: 0x0
Constants:
0: 1
1: None
Expand All @@ -829,7 +829,7 @@ def f(c=c):
Kw-only arguments: 0
Number of locals: 0
Stack size: 2
Flags: NOFREE
Flags: 0x0
Constants:
0: 0
1: 1
Expand All @@ -851,7 +851,7 @@ async def async_def():
Kw-only arguments: 0
Number of locals: 2
Stack size: 10
Flags: OPTIMIZED, NEWLOCALS, NOFREE, COROUTINE
Flags: OPTIMIZED, NEWLOCALS, COROUTINE
Constants:
0: None
1: 1
Expand Down
7 changes: 0 additions & 7 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,6 @@ _PyCode_New(struct _PyCodeConstructor *con)
}
init_code(co, con);

/* Check for any inner or outer closure references */
if (!co->co_ncellvars && !co->co_nfreevars) {
co->co_flags |= CO_NOFREE;
} else {
co->co_flags &= ~CO_NOFREE;
}

return co;
}

Expand Down
2 changes: 1 addition & 1 deletion Programs/test_frozenmain.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Python/frozen_hello.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Auto-generated by Programs/_freeze_importlib.c */
const unsigned char _Py_M__hello[] = {
99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,
0,64,0,0,0,115,16,0,0,0,100,0,90,0,101,1,
0,0,0,0,0,115,16,0,0,0,100,0,90,0,101,1,
100,1,131,1,1,0,100,2,83,0,41,3,84,122,12,72,
101,108,108,111,32,119,111,114,108,100,33,78,41,2,90,11,
105,110,105,116,105,97,108,105,122,101,100,218,5,112,114,105,
Expand Down
Loading