Skip to content

Commit ddc3622

Browse files
committed
Remove unecessary casts, extra imports and unused variables courtesy of Eclipse
1 parent 9e253d1 commit ddc3622

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+125
-156
lines changed

src/org/python/compiler/CodeCompiler.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,6 @@ public Object visitBoolOp(BoolOp node) throws Exception {
13891389
public Object visitCompare(Compare node) throws Exception {
13901390
int tmp1 = code.getLocal("org/python/core/PyObject");
13911391
int tmp2 = code.getLocal("org/python/core/PyObject");
1392-
int op;
13931392

13941393
if (mrefs.nonzero == 0) {
13951394
mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject",
@@ -1756,9 +1755,9 @@ public Object visitCall(Call node) throws Exception {
17561755
public int getslice, setslice, delslice;
17571756
public Object Slice(Subscript node, Slice slice) throws Exception {
17581757
int ctx = node.ctx;
1759-
if (ctx == node.AugStore && augmode == node.Store) {
1758+
if (ctx == expr_contextType.AugStore && augmode == expr_contextType.Store) {
17601759
restoreAugTmps(node, 4);
1761-
ctx = node.Store;
1760+
ctx = expr_contextType.Store;
17621761
} else {
17631762
visit(node.value);
17641763
if (slice.lower != null)
@@ -1774,9 +1773,9 @@ public Object Slice(Subscript node, Slice slice) throws Exception {
17741773
else
17751774
code.aconst_null();
17761775

1777-
if (node.ctx == node.AugStore && augmode == node.Load) {
1776+
if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Load) {
17781777
saveAugTmps(node, 4);
1779-
ctx = node.Load;
1778+
ctx = expr_contextType.Load;
17801779
}
17811780
}
17821781

@@ -1818,16 +1817,16 @@ public Object visitSubscript(Subscript node) throws Exception {
18181817
}
18191818

18201819
int ctx = node.ctx;
1821-
if (node.ctx == node.AugStore && augmode == node.Store) {
1820+
if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Store) {
18221821
restoreAugTmps(node, 2);
1823-
ctx = node.Store;
1822+
ctx = expr_contextType.Store;
18241823
} else {
18251824
visit(node.value);
18261825
visit(node.slice);
18271826

1828-
if (node.ctx == node.AugStore && augmode == node.Load) {
1827+
if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Load) {
18291828
saveAugTmps(node, 2);
1830-
ctx = node.Load;
1829+
ctx = expr_contextType.Load;
18311830
}
18321831
}
18331832

@@ -1883,16 +1882,16 @@ public Object visitExtSlice(ExtSlice node) throws Exception {
18831882
public Object visitAttribute(Attribute node) throws Exception {
18841883

18851884
int ctx = node.ctx;
1886-
if (node.ctx == node.AugStore && augmode == node.Store) {
1885+
if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Store) {
18871886
restoreAugTmps(node, 2);
1888-
ctx = node.Store;
1887+
ctx = expr_contextType.Store;
18891888
} else {
18901889
visit(node.value);
18911890
code.ldc(getName(node.attr));
18921891

1893-
if (node.ctx == node.AugStore && augmode == node.Load) {
1892+
if (node.ctx == expr_contextType.AugStore && augmode == expr_contextType.Load) {
18941893
saveAugTmps(node, 2);
1895-
ctx = node.Load;
1894+
ctx = expr_contextType.Load;
18961895
}
18971896
}
18981897

@@ -1965,8 +1964,8 @@ public Object visitTuple(Tuple node) throws Exception {
19651964
/* if (mode ==AUGSET)
19661965
throw new ParseException(
19671966
"augmented assign to tuple not possible", node); */
1968-
if (node.ctx == node.Store) return seqSet(node.elts);
1969-
if (node.ctx == node.Del) return seqDel(node.elts);
1967+
if (node.ctx == expr_contextType.Store) return seqSet(node.elts);
1968+
if (node.ctx == expr_contextType.Del) return seqDel(node.elts);
19701969

19711970
code.new_(code.pool.Class("org/python/core/PyTuple"));
19721971
code.dup();
@@ -1992,8 +1991,8 @@ public Object visitList(List node) throws Exception {
19921991
throw new ParseException(
19931992
"augmented assign to list not possible", node); */
19941993

1995-
if (node.ctx == node.Store) return seqSet(node.elts);
1996-
if (node.ctx == node.Del) return seqDel(node.elts);
1994+
if (node.ctx == expr_contextType.Store) return seqSet(node.elts);
1995+
if (node.ctx == expr_contextType.Del) return seqDel(node.elts);
19971996

19981997
code.new_(code.pool.Class("org/python/core/PyList"));
19991998
code.dup();
@@ -2248,7 +2247,7 @@ public Object visitName(Name node) throws Exception {
22482247
SymInfo syminf = (SymInfo)tbl.get(name);
22492248

22502249
int ctx = node.ctx;
2251-
if (ctx == node.AugStore) {
2250+
if (ctx == expr_contextType.AugStore) {
22522251
ctx = augmode;
22532252
}
22542253

src/org/python/compiler/Module.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,20 @@ public PyCodeConstant PyCode(modType tree, String name,
465465
if (ac != null && ac.init_code.size() > 0) {
466466
ac.appendInitCode((Suite) tree);
467467
}
468-
469-
if (scope != null) {
470-
int nparamcell = scope.jy_paramcells.size();
471-
if (nparamcell > 0) {
472-
if (to_cell == 0) {
473-
to_cell = classfile.pool.Methodref("org/python/core/PyFrame",
474-
"to_cell","(II)V");
468+
int nparamcell = scope.jy_paramcells.size();
469+
if(nparamcell > 0) {
470+
if(to_cell == 0) {
471+
to_cell = classfile.pool.Methodref("org/python/core/PyFrame", "to_cell", "(II)V");
475472
}
476473
Hashtable tbl = scope.tbl;
477474
Vector paramcells = scope.jy_paramcells;
478-
for (int i = 0; i < nparamcell; i++) {
475+
for(int i = 0; i < nparamcell; i++) {
479476
c.aload(1);
480477
SymInfo syminf = (SymInfo)tbl.get(paramcells.elementAt(i));
481478
c.iconst(syminf.locals_index);
482479
c.iconst(syminf.env_index);
483480
c.invokevirtual(to_cell);
484481
}
485-
}
486482
}
487483

488484
compiler.parse(tree, c, fast_locals, className, classBody,
@@ -510,11 +506,9 @@ public PyCodeConstant PyCode(modType tree, String name,
510506
// !classdef only
511507
if (!classBody) code.names = toNameAr(compiler.names,false);
512508

513-
if (scope != null) {
514-
code.cellvars = toNameAr(scope.cellvars,true);
515-
code.freevars = toNameAr(scope.freevars,true);
516-
code.jy_npurecell = scope.jy_npurecell;
517-
}
509+
code.cellvars = toNameAr(scope.cellvars, true);
510+
code.freevars = toNameAr(scope.freevars, true);
511+
code.jy_npurecell = scope.jy_npurecell;
518512

519513
if (compiler.optimizeGlobals) {
520514
code.moreflags |= org.python.core.PyTableCode.CO_OPTIMIZED;

src/org/python/core/Py.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ public static void runMain(Class mainClass, String[] args,
981981
"$py");
982982
System.exit(-1);
983983
}
984-
PyObject mod = imp.createFromCode("__main__", code);
984+
imp.createFromCode("__main__", code);
985985
} catch (PyException e) {
986986
Py.getSystemState().callExitFunc();
987987
if (Py.matchException(e, Py.SystemExit))
@@ -1093,7 +1093,7 @@ public static void displayException(PyObject type, PyObject value,
10931093

10941094
if (tb instanceof PyTraceback)
10951095
stderr.print(((PyTraceback) tb).dumpStack());
1096-
if (__builtin__.isinstance(value, (PyClass) Py.SyntaxError)) {
1096+
if (__builtin__.isinstance(value, Py.SyntaxError)) {
10971097
stderr.println(" File \""+value.__findattr__("filename")+
10981098
"\", line "+value.__findattr__("lineno"));
10991099
PyObject text = value.__findattr__("text");
@@ -1120,15 +1120,14 @@ public static void displayException(PyObject type, PyObject value,
11201120
static String formatException(PyObject type, PyObject value, PyObject tb) {
11211121
StringBuffer buf = new StringBuffer();
11221122

1123-
PyObject typeName;
11241123
if (type instanceof PyClass) {
11251124
buf.append(((PyClass) type).__name__);
11261125
} else {
11271126
buf.append(type.__str__());
11281127
}
11291128
if (value != Py.None) {
11301129
buf.append(": ");
1131-
if (__builtin__.isinstance(value, (PyClass) Py.SyntaxError)) {
1130+
if (__builtin__.isinstance(value, Py.SyntaxError)) {
11321131
buf.append(value.__getitem__(0).__str__());
11331132
} else {
11341133
buf.append(value.__str__());
@@ -1197,7 +1196,7 @@ public static boolean matchException(PyException pye, PyObject e) {
11971196
}
11981197
}
11991198
if(e instanceof PyClass) {
1200-
return __builtin__.isinstance(pye.value, (PyClass)e);
1199+
return __builtin__.isinstance(pye.value, e);
12011200
} else {
12021201
if(e == pye.type)
12031202
return true;
@@ -1286,7 +1285,7 @@ public static PyObject runCode(PyCode code, PyObject locals,
12861285
tc = (PyTableCode)code;
12871286

12881287
f = new PyFrame(tc, locals, globals,
1289-
Py.getThreadState().systemState.builtins);
1288+
PySystemState.builtins);
12901289
return code.call(f);
12911290
}
12921291

@@ -1459,7 +1458,7 @@ public static int py2int(PyObject o) {
14591458

14601459
public static int py2int(PyObject o, String msg) {
14611460
if (o instanceof PyInteger)
1462-
return (int)((PyInteger)o).getValue();
1461+
return ((PyInteger)o).getValue();
14631462
Object obj = o.__tojava__(Integer.TYPE);
14641463
if (obj == Py.NoConversion)
14651464
throw Py.TypeError(msg);
@@ -1468,7 +1467,7 @@ public static int py2int(PyObject o, String msg) {
14681467

14691468
public static long py2long(PyObject o) {
14701469
if(o instanceof PyInteger)
1471-
return (long)((PyInteger)o).getValue();
1470+
return ((PyInteger)o).getValue();
14721471

14731472
Object i = o.__tojava__(Long.TYPE);
14741473
if (i == null || i == Py.NoConversion)
@@ -1480,7 +1479,7 @@ public static float py2float(PyObject o) {
14801479
if (o instanceof PyFloat)
14811480
return (float)((PyFloat)o).getValue();
14821481
if (o instanceof PyInteger)
1483-
return (float)((PyInteger)o).getValue();
1482+
return ((PyInteger)o).getValue();
14841483

14851484
Object i = o.__tojava__(Float.TYPE);
14861485
if (i == null || i == Py.NoConversion)
@@ -1489,9 +1488,9 @@ public static float py2float(PyObject o) {
14891488
}
14901489
public static double py2double(PyObject o) {
14911490
if (o instanceof PyFloat)
1492-
return (double)((PyFloat)o).getValue();
1491+
return ((PyFloat)o).getValue();
14931492
if (o instanceof PyInteger)
1494-
return (double)((PyInteger)o).getValue();
1493+
return ((PyInteger)o).getValue();
14951494

14961495
Object i = o.__tojava__(Double.TYPE);
14971496
if (i == null || i == Py.NoConversion)

src/org/python/core/PyBeanProperty.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public PyObject _doget(PyObject self) {
3131
Object iself = Py.tojava(self, getMethod.getDeclaringClass());
3232

3333
try {
34-
Object value = getMethod.invoke(iself, (Object[])Py.EmptyObjects);
34+
Object value = getMethod.invoke(iself, Py.EmptyObjects);
3535
return Py.java2py(value);
3636
} catch (Exception e) {
3737
throw Py.JavaError(e);
@@ -52,10 +52,7 @@ public boolean _doset(PyObject self, PyObject value) {
5252

5353
Object iself = Py.tojava(self, setMethod.getDeclaringClass());
5454

55-
Object jvalue=null;
56-
57-
// Special handling of tuples
58-
// try to call a class constructor
55+
// Special handling of tuples - try to call a class constructor
5956
if (value instanceof PyTuple) {
6057
try {
6158
PyTuple vtup = (PyTuple)value;
@@ -64,9 +61,7 @@ public boolean _doset(PyObject self, PyObject value) {
6461
// If something goes wrong ignore it?
6562
}
6663
}
67-
if (jvalue == null) {
68-
jvalue = Py.tojava(value, myType);
69-
}
64+
Object jvalue = Py.tojava(value, myType);
7065

7166
try {
7267
setMethod.invoke(iself, new Object[] {jvalue});

src/org/python/core/PyCallIter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
public class PyCallIter extends PyIterator {
44
private PyObject callable;
55
private PyObject sentinel;
6-
private int idx;
76

87
public PyCallIter(PyObject callable, PyObject sentinel) {
98
if(!__builtin__.callable(callable)) {

src/org/python/core/PyComplex.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ public Object __coerce_ex__(PyObject other) {
921921
if (other instanceof PyFloat)
922922
return new PyComplex(((PyFloat)other).getValue(), 0);
923923
if (other instanceof PyInteger)
924-
return new PyComplex((double)((PyInteger)other).getValue(), 0);
924+
return new PyComplex(((PyInteger)other).getValue(), 0);
925925
if (other instanceof PyLong)
926926
return new PyComplex(((PyLong)other).doubleValue(), 0);
927927
return Py.None;
@@ -940,7 +940,7 @@ private final PyComplex coerce(PyObject other) {
940940
if (other instanceof PyFloat)
941941
return new PyComplex(((PyFloat)other).getValue(), 0);
942942
if (other instanceof PyInteger)
943-
return new PyComplex((double)((PyInteger)other).getValue(), 0);
943+
return new PyComplex(((PyInteger)other).getValue(), 0);
944944
if (other instanceof PyLong)
945945
return new PyComplex(((PyLong)other).doubleValue(), 0);
946946
throw Py.TypeError("xxx");
@@ -1233,7 +1233,7 @@ public static PyObject _pow(PyComplex value, PyComplex right) {
12331233

12341234
// Check for integral powers
12351235
int iexp = (int)yr;
1236-
if (yi == 0 && yr == (double)iexp && iexp >= -128 && iexp <= 128) {
1236+
if (yi == 0 && yr == iexp && iexp >= -128 && iexp <= 128) {
12371237
return ipow(value, iexp);
12381238
}
12391239

src/org/python/core/PyException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void instantiate() {
3535
}
3636
if (type instanceof PyClass &&
3737
(!(value instanceof PyInstance &&
38-
__builtin__.isinstance(value, (PyClass)type))))
38+
__builtin__.isinstance(value, type))))
3939
{
4040
//System.out.println("value: "+value);
4141
if (value instanceof PyTuple) {

src/org/python/core/PyFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ private int readBytes( byte b[], int off, int len )
349349
public int read() throws java.io.IOException {
350350
// If the file position is within the data, return the byte...
351351
if (filePosition < dataEnd) {
352-
return (int)(buffer[(int)(filePosition++ - bufferStart)]
352+
return (buffer[(int)(filePosition++ - bufferStart)]
353353
& 0xff);
354354
} else if (endOfFile) {
355355
// ...or should we indicate EOF...
@@ -472,7 +472,7 @@ public void flush() throws java.io.IOException {
472472
public void close() throws java.io.IOException {
473473
if (writing && bufferModified) {
474474
file.seek(bufferStart);
475-
file.write(buffer, 0, (int)dataSize);
475+
file.write(buffer, 0, dataSize);
476476
}
477477

478478
file.close();

src/org/python/core/PyFrame.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public PyObject getglobal(String index) {
194194

195195
// Set up f_builtins if not already set
196196
if (f_builtins == null) {
197-
f_builtins = Py.getSystemState().builtins;
197+
f_builtins = PySystemState.builtins;
198198
}
199199
ret = f_builtins.__finditem__(index);
200200
if (ret != null) return ret;

src/org/python/core/PyInstance.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ private void writeObject(java.io.ObjectOutputStream out)
5151
//System.out.println("writing: "+getClass().getName());
5252
out.defaultWriteObject();
5353
PyObject name = instclass.__findattr__("__module__");
54-
if (!(name instanceof PyString) || name == Py.None || name == null) {
54+
if (!(name instanceof PyString) || name == Py.None) {
5555
throw Py.ValueError("Can't find module for class: "+
5656
instclass.__name__);
5757
}
5858
out.writeUTF(name.toString());
5959
name = instclass.__findattr__("__name__");
60-
if (!(name instanceof PyString) || name == Py.None || name == null) {
60+
if (!(name instanceof PyString) || name == Py.None) {
6161
throw Py.ValueError("Can't find module for class with no name");
6262
}
6363

@@ -757,7 +757,7 @@ public PyString __oct__() {
757757
public PyObject __int__() {
758758
PyObject ret = invoke("__int__");
759759
if (ret instanceof PyInteger)
760-
return (PyInteger)ret;
760+
return ret;
761761
throw Py.TypeError("__int__() should return a int");
762762
}
763763

0 commit comments

Comments
 (0)