Skip to content

Commit e867ef0

Browse files
author
Drew O'Meara
committed
resolved benign Go warnings
1 parent 965bc08 commit e867ef0

File tree

12 files changed

+17
-21
lines changed

12 files changed

+17
-21
lines changed

builtin/builtin.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ func builtin_compile(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Ob
749749
return nil, py.ExceptionNewf(py.ValueError, "compile(): invalid optimize value")
750750
}
751751

752-
if dont_inherit.(py.Int) != 0 {
752+
// if dont_inherit.(py.Int) != 0 {
753753
// PyEval_MergeCompilerFlags(&cf)
754-
}
754+
// }
755755

756756
// switch string(startstr.(py.String)) {
757757
// case "exec":
@@ -882,9 +882,8 @@ or ... etc.
882882
`
883883

884884
func isinstance(obj py.Object, classOrTuple py.Object) (py.Bool, error) {
885-
switch classOrTuple.(type) {
885+
switch class_tuple := classOrTuple.(type) {
886886
case py.Tuple:
887-
var class_tuple = classOrTuple.(py.Tuple)
888887
for idx := range class_tuple {
889888
res, _ := isinstance(obj, class_tuple[idx])
890889
if res {

compile/compile.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,6 @@ func (c *compiler) NameOp(name string, ctx ast.ExprContext) {
13421342
default:
13431343
panic("NameOp: ctx invalid for name variable")
13441344
}
1345-
break
13461345
}
13471346
if op == 0 {
13481347
panic("NameOp: Op not set")

compile/instructions_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestLnotab(t *testing.T) {
5353
},
5454
} {
5555
got := test.instrs.Lnotab()
56-
if bytes.Compare(test.want, got) != 0 {
56+
if !bytes.Equal(test.want, got) {
5757
t.Errorf("%d: want %d got %d", i, test.want, got)
5858
}
5959
}

marshal/marshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func ReadPyc(r io.Reader) (obj py.Object, err error) {
448448
}
449449
// FIXME do something with timestamp & length?
450450
if header.Magic>>16 != 0x0a0d {
451-
return nil, errors.New("Bad magic in .pyc file")
451+
return nil, errors.New("bad magic in .pyc file")
452452
}
453453
// fmt.Printf("header = %v\n", header)
454454
return ReadObject(r)

parser/stringescape.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func DecodeEscape(in *bytes.Buffer, byteMode bool) (out *bytes.Buffer, err error
1818
// Early exit if no escape sequences
1919
// NB in.Bytes() is cheap
2020
inBytes := in.Bytes()
21-
if bytes.IndexRune(inBytes, '\\') < 0 {
21+
if !bytes.ContainsRune(inBytes, '\\') {
2222
return in, nil
2323
}
2424
out = new(bytes.Buffer)
@@ -135,7 +135,6 @@ func DecodeEscape(in *bytes.Buffer, byteMode bool) (out *bytes.Buffer, err error
135135
ignoreEscape = true
136136
default:
137137
ignoreEscape = true
138-
break
139138
}
140139
// ignore unrecognised escape
141140
if ignoreEscape {

py/bytes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ func (a Bytes) M__le__(other Object) (Object, error) {
214214

215215
func (a Bytes) M__eq__(other Object) (Object, error) {
216216
if b, ok := convertToBytes(other); ok {
217-
return NewBool(bytes.Compare(a, b) == 0), nil
217+
return NewBool(bytes.Equal(a, b)), nil
218218
}
219219
return NotImplemented, nil
220220
}
221221

222222
func (a Bytes) M__ne__(other Object) (Object, error) {
223223
if b, ok := convertToBytes(other); ok {
224-
return NewBool(bytes.Compare(a, b) != 0), nil
224+
return NewBool(!bytes.Equal(a, b)), nil
225225
}
226226
return NotImplemented, nil
227227
}

py/code.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const NAME_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvw
9797
// all_name_chars(s): true iff all chars in s are valid NAME_CHARS
9898
func all_name_chars(s String) bool {
9999
for _, c := range s {
100-
if strings.IndexRune(NAME_CHARS, c) < 0 {
100+
if !strings.ContainsRune(NAME_CHARS, c) {
101101
return false
102102
}
103103
}

py/int.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ func (a Int) M__pos__() (Object, error) {
254254

255255
func (a Int) M__abs__() (Object, error) {
256256
if a == IntMin {
257-
// FIXME upconvert
257+
abig, _ := ConvertToBigInt(a)
258+
return abig.M__abs__()
258259
}
259260
if a < 0 {
260261
return -a, nil

py/method.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func newBoundMethod(name string, fn interface{}) (Object, error) {
224224
return f(a, b, c)
225225
}
226226
default:
227-
return nil, fmt.Errorf("Unknown bound method type for %q: %T", name, fn)
227+
return nil, fmt.Errorf("unknown bound method type for %q: %T", name, fn)
228228
}
229229
return m, nil
230230
}

py/range.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ func computeRangeLength(start, stop, step Int) Int {
146146
if step > 0 {
147147
lo = start
148148
hi = stop
149-
step = step
150149
} else {
151150
lo = stop
152151
hi = start

py/string.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func StringEscape(a String, ascii bool) string {
9494
func fieldsN(s string, n int) []string {
9595
out := []string{}
9696
cur := []rune{}
97-
r := []rune(s)
98-
for _, c := range r {
97+
for _, c := range s {
9998
//until we have covered the first N elements, multiple white-spaces are 'merged'
10099
if n < 0 || len(out) < n {
101100
if unicode.IsSpace(c) {
@@ -139,7 +138,7 @@ func init() {
139138
maxSplit = int(m)
140139
}
141140
}
142-
valArray := []string{}
141+
var valArray []string
143142
if valStr, ok := value.(String); ok {
144143
valArray = strings.SplitN(string(selfStr), string(valStr), maxSplit+1)
145144
} else if _, ok := value.(NoneType); ok {

vm/eval.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,9 +1087,9 @@ func do_IMPORT_NAME(vm *Vm, namei int32) error {
10871087
}
10881088
v := vm.POP()
10891089
u := vm.TOP()
1090-
var locals py.Object = vm.frame.Locals
1091-
if locals == nil {
1092-
locals = py.None
1090+
var locals py.Object = py.None
1091+
if vm.frame.Locals != nil {
1092+
locals = vm.frame.Locals
10931093
}
10941094
var args py.Tuple
10951095
if _, ok := u.(py.Int); ok {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy