Skip to content

Commit a34e8bf

Browse files
committed
comment out lagacy future feature flags
1 parent 7da7167 commit a34e8bf

10 files changed

+90
-81
lines changed

src/org/python/Version.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public class Version {
4646

4747
/** The flags that are set by default in a code object. */
4848
private static final Collection<CodeFlag> defaultCodeFlags = Arrays.asList(
49-
CodeFlag.CO_NESTED,
50-
CodeFlag.CO_GENERATOR_ALLOWED,
51-
CodeFlag.CO_FUTURE_WITH_STATEMENT,
52-
CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT,
53-
CodeFlag.CO_FUTURE_DIVISION,
54-
CodeFlag.CO_FUTURE_PRINT_FUNCTION,
55-
CodeFlag.CO_FUTURE_UNICODE_LITERALS
49+
CodeFlag.CO_NESTED
50+
// CodeFlag.CO_GENERATOR_ALLOWED,
51+
// CodeFlag.CO_FUTURE_WITH_STATEMENT,
52+
// CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT,
53+
// CodeFlag.CO_FUTURE_DIVISION,
54+
// CodeFlag.CO_FUTURE_PRINT_FUNCTION,
55+
// CodeFlag.CO_FUTURE_UNICODE_LITERALS
5656
);
5757

5858
static {

src/org/python/compiler/CodeCompiler.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ public Object visitBinOp(BinOp node) throws Exception {
17611761
name = "_matmul";
17621762
break;
17631763
case Div:
1764-
name = "_div";
1764+
name = "_truediv";
17651765
break;
17661766
case Mod:
17671767
name = "_mod";
@@ -1789,9 +1789,9 @@ public Object visitBinOp(BinOp node) throws Exception {
17891789
break;
17901790
}
17911791

1792-
if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) {
1793-
name = "_truediv";
1794-
}
1792+
// if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) {
1793+
// name = "_truediv";
1794+
// }
17951795
code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class));
17961796
return null;
17971797
}
@@ -1872,9 +1872,9 @@ public Object visitAugAssign(AugAssign node) throws Exception {
18721872
name = "_ifloordiv";
18731873
break;
18741874
}
1875-
if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) {
1876-
name = "_itruediv";
1877-
}
1875+
// if (node.getInternalOp() == operatorType.Div && module.getFutures().areDivisionOn()) {
1876+
// name = "_itruediv";
1877+
// }
18781878
code.invokevirtual(p(PyObject.class), name, sig(PyObject.class, PyObject.class));
18791879
code.freeLocal(target);
18801880

src/org/python/compiler/Future.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ private boolean check(ImportFrom cand) throws Exception {
5454
public void preprocessFutures(mod node, org.python.core.CompilerFlags cflags)
5555
throws Exception {
5656
if (cflags != null) {
57-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION))
58-
FutureFeature.division.addTo(features);
59-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT))
60-
FutureFeature.with_statement.addTo(features);
61-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT))
62-
FutureFeature.absolute_import.addTo(features);
63-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_PRINT_FUNCTION))
64-
FutureFeature.print_function.addTo(features);
65-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_UNICODE_LITERALS))
66-
FutureFeature.unicode_literals.addTo(features);
57+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION))
58+
// FutureFeature.division.addTo(features);
59+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT))
60+
// FutureFeature.with_statement.addTo(features);
61+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT))
62+
// FutureFeature.absolute_import.addTo(features);
63+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_PRINT_FUNCTION))
64+
// FutureFeature.print_function.addTo(features);
65+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_UNICODE_LITERALS))
66+
// FutureFeature.unicode_literals.addTo(features);
6767
}
6868
int beg = 0;
6969
List<stmt> suite = null;
@@ -102,15 +102,15 @@ public static void checkFromFuture(ImportFrom node) throws Exception {
102102
node.from_future_checked = true;
103103
}
104104

105-
public boolean areDivisionOn() {
106-
return featureSet.contains(FutureFeature.division);
107-
}
108-
109-
public boolean withStatementSupported() {
110-
return featureSet.contains(FutureFeature.with_statement);
111-
}
105+
// public boolean areDivisionOn() {
106+
// return featureSet.contains(FutureFeature.division);
107+
// }
112108

113-
public boolean isAbsoluteImportOn() {
114-
return featureSet.contains(FutureFeature.absolute_import);
115-
}
109+
// public boolean withStatementSupported() {
110+
// return featureSet.contains(FutureFeature.with_statement);
111+
// }
112+
//
113+
// public boolean isAbsoluteImportOn() {
114+
// return featureSet.contains(FutureFeature.absolute_import);
115+
// }
116116
}

src/org/python/compiler/Module.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ class PyCodeConstant extends Constant implements ClassConstants, Opcodes {
265265
PyCodeConstant(mod tree, String name, boolean fast_locals, String className, boolean classBody,
266266
boolean printResults, int firstlineno, ScopeInfo scope, CompilerFlags cflags,
267267
Module module) throws Exception {
268-
269268
this.co_name = name;
270269
this.co_firstlineno = firstlineno;
271270
this.module = module;
@@ -317,22 +316,30 @@ class PyCodeConstant extends Constant implements ClassConstants, Opcodes {
317316
jy_npurecell = scope.jy_npurecell;
318317

319318
if (CodeCompiler.checkOptimizeGlobals(fast_locals, scope)) {
320-
_moreflags |= CodeFlag.CO_OPTIMIZED.flag;
319+
_moreflags |= CodeFlag.CO_OPTIMIZED.flag | CodeFlag.CO_NEWLOCALS.flag;
320+
}
321+
322+
if (scope.isNested()) {
323+
_moreflags |= CodeFlag.CO_NESTED.flag;
324+
}
325+
326+
if (scope.freevars.isEmpty() && scope.cellvars.isEmpty()) {
327+
_moreflags |= CodeFlag.CO_NOFREE.flag;
321328
}
322329

323330
if (scope.async) {
324331
_moreflags |= CodeFlag.CO_COROUTINE.flag;
325332
} else if (scope.generator) {
326333
_moreflags |= CodeFlag.CO_GENERATOR.flag;
327334
}
328-
if (cflags != null) {
329-
if (cflags.isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED)) {
330-
_moreflags |= CodeFlag.CO_GENERATOR_ALLOWED.flag;
331-
}
332-
if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) {
333-
_moreflags |= CodeFlag.CO_FUTURE_DIVISION.flag;
334-
}
335-
}
335+
// if (cflags != null) {
336+
// if (cflags.isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED)) {
337+
// _moreflags |= CodeFlag.CO_GENERATOR_ALLOWED.flag;
338+
// }
339+
// if (cflags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) {
340+
// _moreflags |= CodeFlag.CO_FUTURE_DIVISION.flag;
341+
// }
342+
// }
336343
moreflags = _moreflags;
337344
}
338345

@@ -437,7 +444,6 @@ void put(Code c) throws IOException {
437444
}
438445
}
439446

440-
441447
public class Module implements Opcodes, ClassConstants, CompilationContext {
442448

443449
ClassFile classfile;

src/org/python/compiler/ScopeInfo.java

+4
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,8 @@ public void noteReturnValue() {
314314
public boolean isFunction() {
315315
return kind == FUNCSCOPE;
316316
}
317+
318+
public boolean isNested() {
319+
return isFunction() && up.isFunction();
320+
}
317321
}

src/org/python/core/CodeFlag.java

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public enum CodeFlag {
3434
* Denotes that nested scopes are enabled in the code block.
3535
*/
3636
CO_NESTED(0x0010),
37+
38+
/**
39+
* The flag is set if there are no free or cell variables.
40+
*/
41+
CO_NOFREE(0x0040),
3742
/**
3843
* The CO_COROUTINE flag is set for coroutine functions (defined with
3944
* ``async def`` keywords)

src/org/python/core/CompilerFlags.java

+20-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.python.core;
88

99
import java.io.Serializable;
10+
import java.util.HashSet;
1011
import java.util.Set;
1112

1213
import org.python.Version;
@@ -21,7 +22,8 @@ public class CompilerFlags implements Serializable {
2122
public boolean source_is_utf8;
2223

2324
public String encoding;
24-
private final Set<CodeFlag> flags = Version.getDefaultCodeFlags();
25+
// private final Set<CodeFlag> flags = Version.getDefaultCodeFlags();
26+
private final Set<CodeFlag> flags = new HashSet<>();
2527

2628
public CompilerFlags() {
2729
}
@@ -60,16 +62,17 @@ public boolean isFlagSet(CodeFlag flag) {
6062
@Override
6163
public String toString() {
6264
return String.format(
63-
"CompilerFlags[division=%s nested_scopes=%s generators=%s "
64-
+ "with_statement=%s absolute_import=%s only_ast=%s "
65-
+ "dont_imply_dedent=%s source_is_utf8=%s]",
66-
isFlagSet(CodeFlag.CO_FUTURE_DIVISION),
65+
"CompilerFlags[nested_scopes=%s only_ast=%s dont_imply_dedent=%s source_is_utf8=%s]",
66+
// "CompilerFlags[division=%s nested_scopes=%s generators=%s "
67+
// + "with_statement=%s absolute_import=%s only_ast=%s "
68+
// + "dont_imply_dedent=%s source_is_utf8=%s]",
69+
// isFlagSet(CodeFlag.CO_FUTURE_DIVISION),
6770
isFlagSet(CodeFlag.CO_NESTED),
68-
isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED),
69-
isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT),
70-
isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT),
71-
isFlagSet(CodeFlag.CO_FUTURE_PRINT_FUNCTION),
72-
isFlagSet(CodeFlag.CO_FUTURE_UNICODE_LITERALS),
71+
// isFlagSet(CodeFlag.CO_GENERATOR_ALLOWED),
72+
// isFlagSet(CodeFlag.CO_FUTURE_WITH_STATEMENT),
73+
// isFlagSet(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT),
74+
// isFlagSet(CodeFlag.CO_FUTURE_PRINT_FUNCTION),
75+
// isFlagSet(CodeFlag.CO_FUTURE_UNICODE_LITERALS),
7376
only_ast,
7477
dont_imply_dedent,
7578
source_is_utf8);
@@ -82,13 +85,13 @@ public static CompilerFlags getCompilerFlags() {
8285
private static final int CO_ALL_FEATURES = CompilerFlags.PyCF_DONT_IMPLY_DEDENT
8386
| CompilerFlags.PyCF_ONLY_AST
8487
| CompilerFlags.PyCF_SOURCE_IS_UTF8
85-
| CodeFlag.CO_NESTED.flag
86-
| CodeFlag.CO_GENERATOR_ALLOWED.flag
87-
| CodeFlag.CO_FUTURE_DIVISION.flag
88-
| CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT.flag
89-
| CodeFlag.CO_FUTURE_WITH_STATEMENT.flag
90-
| CodeFlag.CO_FUTURE_PRINT_FUNCTION.flag
91-
| CodeFlag.CO_FUTURE_UNICODE_LITERALS.flag;
88+
| CodeFlag.CO_NESTED.flag;
89+
// | CodeFlag.CO_GENERATOR_ALLOWED.flag
90+
// | CodeFlag.CO_FUTURE_DIVISION.flag
91+
// | CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT.flag
92+
// | CodeFlag.CO_FUTURE_WITH_STATEMENT.flag
93+
// | CodeFlag.CO_FUTURE_PRINT_FUNCTION.flag
94+
// | CodeFlag.CO_FUTURE_UNICODE_LITERALS.flag;
9295

9396
public static CompilerFlags getCompilerFlags(int flags, PyFrame frame) {
9497
if ((flags & ~CO_ALL_FEATURES) != 0) {

src/org/python/core/FutureFeature.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ public enum FutureFeature implements Pragma {
66
/**
77
* Enables nested scopes.
88
*/
9-
nested_scopes(CodeFlag.CO_NESTED),
9+
// nested_scopes(CodeFlag.CO_NESTED),
1010
/**
1111
* Makes integer / integer division return float.
1212
*/
13-
division(CodeFlag.CO_FUTURE_DIVISION),
13+
// division(CodeFlag.CO_FUTURE_DIVISION),
1414
/**
1515
* Enables generators.
1616
*/
17-
generators(CodeFlag.CO_GENERATOR_ALLOWED),
17+
// generators(CodeFlag.CO_GENERATOR_ALLOWED),
1818
/**
1919
* Enables absolute imports.
2020
*/
21-
absolute_import(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT),
21+
// absolute_import(CodeFlag.CO_FUTURE_ABSOLUTE_IMPORT),
2222
/**
2323
* Enables the with statement.
2424
*/
25-
with_statement(CodeFlag.CO_FUTURE_WITH_STATEMENT),
25+
// with_statement(CodeFlag.CO_FUTURE_WITH_STATEMENT),
2626
/**
2727
* Enables the print function.
2828
*/
29-
print_function(CodeFlag.CO_FUTURE_PRINT_FUNCTION),
29+
// print_function(CodeFlag.CO_FUTURE_PRINT_FUNCTION),
3030
/**
3131
* Enables unicode literals.
3232
*/
33-
unicode_literals(CodeFlag.CO_FUTURE_UNICODE_LITERALS),
33+
// unicode_literals(CodeFlag.CO_FUTURE_UNICODE_LITERALS),
3434
/**
3535
* Use braces for block delimiters instead of indentation.
3636
*/

src/org/python/core/PyBytecode.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,7 @@ protected PyObject interpret(PyFrame f, ThreadState ts) {
432432
case Opcode.BINARY_DIVIDE: {
433433
PyObject b = stack.pop();
434434
PyObject a = stack.pop();
435-
436-
if (!co_flags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) {
437-
stack.push(a._div(b));
438-
} else {
439-
stack.push(a._truediv(b));
440-
}
435+
stack.push(a._truediv(b));
441436
break;
442437
}
443438

@@ -543,11 +538,7 @@ protected PyObject interpret(PyFrame f, ThreadState ts) {
543538
case Opcode.INPLACE_DIVIDE: {
544539
PyObject b = stack.pop();
545540
PyObject a = stack.pop();
546-
if (!co_flags.isFlagSet(CodeFlag.CO_FUTURE_DIVISION)) {
547-
stack.push(a._idiv(b));
548-
} else {
549-
stack.push(a._itruediv(b));
550-
}
541+
stack.push(a._itruediv(b));
551542
break;
552543
}
553544

src/org/python/util/jython.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public static void run(String[] args) {
294294
Options.division_warning = 2;
295295
} else if ("new".equals(opts.division)) {
296296
Options.Qnew = true;
297-
interp.cflags.setFlag(CodeFlag.CO_FUTURE_DIVISION);
297+
// interp.cflags.setFlag(CodeFlag.CO_FUTURE_DIVISION);
298298
}
299299
}
300300

0 commit comments

Comments
 (0)