Skip to content

Commit 769d7d0

Browse files
authored
bpo-43693 Get rid of CO_NOFREE -- it's unused (GH-26839)
All uses of this flag are either setting it or in doc or tests for it. So we should be able to get rid of it completely.
1 parent 34356a0 commit 769d7d0

File tree

10 files changed

+239
-260
lines changed

10 files changed

+239
-260
lines changed

Doc/library/inspect.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,6 @@ the following flags:
14501450
The flag is set when the code object is a generator function, i.e.
14511451
a generator object is returned when the code object is executed.
14521452

1453-
.. data:: CO_NOFREE
1454-
1455-
The flag is set if there are no free or cell variables.
1456-
14571453
.. data:: CO_COROUTINE
14581454

14591455
The flag is set when the code object is a coroutine function.

Include/cpython/code.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ struct PyCodeObject {
112112
#define CO_VARKEYWORDS 0x0008
113113
#define CO_NESTED 0x0010
114114
#define CO_GENERATOR 0x0020
115-
/* The CO_NOFREE flag is set if there are no free or cell variables.
116-
This information is redundant, but it allows a single flag test
117-
to determine whether there is any extra work to be done when the
118-
call frame it setup.
119-
*/
120-
#define CO_NOFREE 0x0040
121115

122116
/* The CO_COROUTINE flag is set for coroutine functions (defined with
123117
``async def`` keywords) */

Lib/test/test_code.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
cellvars: ()
5050
freevars: ()
5151
nlocals: 5
52-
flags: 67
52+
flags: 3
5353
consts: ('None',)
5454
5555
>>> def attrs(obj):
@@ -67,7 +67,7 @@
6767
cellvars: ()
6868
freevars: ()
6969
nlocals: 1
70-
flags: 67
70+
flags: 3
7171
consts: ('None',)
7272
7373
>>> def optimize_away():
@@ -86,7 +86,7 @@
8686
cellvars: ()
8787
freevars: ()
8888
nlocals: 0
89-
flags: 67
89+
flags: 3
9090
consts: ("'doc string'", 'None')
9191
9292
>>> def keywordonly_args(a,b,*,k1):
@@ -103,7 +103,7 @@
103103
cellvars: ()
104104
freevars: ()
105105
nlocals: 3
106-
flags: 67
106+
flags: 3
107107
consts: ('None',)
108108
109109
>>> def posonly_args(a,b,/,c):
@@ -120,7 +120,7 @@
120120
cellvars: ()
121121
freevars: ()
122122
nlocals: 3
123-
flags: 67
123+
flags: 3
124124
consts: ('None',)
125125
126126
"""
@@ -199,10 +199,6 @@ class List(list):
199199
class_ref = function.__closure__[0].cell_contents
200200
self.assertIs(class_ref, List)
201201

202-
# Ensure the code correctly indicates it accesses a free variable
203-
self.assertFalse(function.__code__.co_flags & inspect.CO_NOFREE,
204-
hex(function.__code__.co_flags))
205-
206202
# Ensure the zero-arg super() call in the injected method works
207203
obj = List([1, 2, 3])
208204
self.assertEqual(obj[0], "Foreign getitem: 1")

Lib/test/test_dis.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ def get_disassembly(self, func, lasti=-1, wrapper=True, **kwargs):
719719
Kw-only arguments: 0
720720
Number of locals: 1
721721
Stack size: 3
722-
Flags: OPTIMIZED, NEWLOCALS, NOFREE
722+
Flags: OPTIMIZED, NEWLOCALS
723723
Constants:
724724
{code_info_consts}
725725
Names:
@@ -800,7 +800,7 @@ def f(c=c):
800800
Kw-only arguments: 0
801801
Number of locals: 0
802802
Stack size: 2
803-
Flags: NOFREE
803+
Flags: 0x0
804804
Constants:
805805
0: 1
806806
Names:
@@ -814,7 +814,7 @@ def f(c=c):
814814
Kw-only arguments: 0
815815
Number of locals: 0
816816
Stack size: 2
817-
Flags: NOFREE
817+
Flags: 0x0
818818
Constants:
819819
0: 1
820820
1: None
@@ -829,7 +829,7 @@ def f(c=c):
829829
Kw-only arguments: 0
830830
Number of locals: 0
831831
Stack size: 2
832-
Flags: NOFREE
832+
Flags: 0x0
833833
Constants:
834834
0: 0
835835
1: 1
@@ -851,7 +851,7 @@ async def async_def():
851851
Kw-only arguments: 0
852852
Number of locals: 2
853853
Stack size: 10
854-
Flags: OPTIMIZED, NEWLOCALS, NOFREE, COROUTINE
854+
Flags: OPTIMIZED, NEWLOCALS, COROUTINE
855855
Constants:
856856
0: None
857857
1: 1

Objects/codeobject.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -372,13 +372,6 @@ _PyCode_New(struct _PyCodeConstructor *con)
372372
}
373373
init_code(co, con);
374374

375-
/* Check for any inner or outer closure references */
376-
if (!co->co_ncellvars && !co->co_nfreevars) {
377-
co->co_flags |= CO_NOFREE;
378-
} else {
379-
co->co_flags &= ~CO_NOFREE;
380-
}
381-
382375
return co;
383376
}
384377

Programs/test_frozenmain.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/frozen_hello.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Auto-generated by Programs/_freeze_importlib.c */
22
const unsigned char _Py_M__hello[] = {
33
99,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,
4-
0,64,0,0,0,115,16,0,0,0,100,0,90,0,101,1,
4+
0,0,0,0,0,115,16,0,0,0,100,0,90,0,101,1,
55
100,1,131,1,1,0,100,2,83,0,41,3,84,122,12,72,
66
101,108,108,111,32,119,111,114,108,100,33,78,41,2,90,11,
77
105,110,105,116,105,97,108,105,122,101,100,218,5,112,114,105,

0 commit comments

Comments
 (0)