Skip to content

Commit 8f39572

Browse files
committed
bpo-40366: Remove support for passing CO_NESTED as a flag to compile
1 parent 458004b commit 8f39572

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

Doc/whatsnew/3.9.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@ Removed
791791
deprecated since 2006, and only returning ``False`` when it's called.
792792
(Contributed by Batuhan Taskaya in :issue:`40208`)
793793

794+
* Support for passing ``CO_NESTED`` flag to :func:`compile` has been removed.
795+
It was obsolete and the default behavior since Python 2.2, 19 years.
796+
(Contributed by Batuhan Taskaya in :issue:`40366`)
794797

795798
Porting to Python 3.9
796799
=====================

Include/compile.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ PyAPI_FUNC(PyCodeObject *) PyNode_Compile(struct _node *, const char *);
1717
CO_FUTURE_WITH_STATEMENT | CO_FUTURE_PRINT_FUNCTION | \
1818
CO_FUTURE_UNICODE_LITERALS | CO_FUTURE_BARRY_AS_BDFL | \
1919
CO_FUTURE_GENERATOR_STOP | CO_FUTURE_ANNOTATIONS)
20-
#define PyCF_MASK_OBSOLETE (CO_NESTED)
2120

2221
/* bpo-39562: CO_FUTURE_ and PyCF_ constants must be kept unique.
2322
PyCF_ constants can use bits from 0x0100 to 0x10000.

Lib/test/test_builtin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import warnings
2121
from contextlib import ExitStack
2222
from functools import partial
23-
from inspect import CO_COROUTINE
23+
from inspect import CO_COROUTINE, CO_NESTED
2424
from itertools import product
2525
from textwrap import dedent
2626
from types import AsyncGeneratorType, FunctionType
@@ -339,6 +339,7 @@ def test_compile(self):
339339
compile('print("\xe5")\n', '', 'exec')
340340
self.assertRaises(ValueError, compile, chr(0), 'f', 'exec')
341341
self.assertRaises(ValueError, compile, str('a = 1'), 'f', 'bad')
342+
self.assertRaises(ValueError, compile, 'obsolote_flag', 'f', 'exec', CO_NESTED)
342343

343344
# test the optimize argument
344345

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed support for ``CO_NESTED`` flag in :func:`compile`.

Python/bltinmodule.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,11 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
738738
cf.cf_feature_version = feature_version;
739739
}
740740

741-
if (flags &
742-
~(PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_COMPILE_MASK))
743-
{
741+
if (flags & ~(PyCF_MASK | PyCF_COMPILE_MASK)) {
744742
PyErr_SetString(PyExc_ValueError,
745743
"compile(): unrecognised flags");
746744
goto error;
747745
}
748-
/* XXX Warn if (supplied_flags & PyCF_MASK_OBSOLETE) != 0? */
749746

750747
if (optimize < -1 || optimize > 2) {
751748
PyErr_SetString(PyExc_ValueError,

Python/ceval.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4913,12 +4913,6 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
49134913
result = 1;
49144914
cf->cf_flags |= compilerflags;
49154915
}
4916-
#if 0 /* future keyword */
4917-
if (codeflags & CO_GENERATOR_ALLOWED) {
4918-
result = 1;
4919-
cf->cf_flags |= CO_GENERATOR_ALLOWED;
4920-
}
4921-
#endif
49224916
}
49234917
return result;
49244918
}

0 commit comments

Comments
 (0)