Skip to content

resolved benign Go warnings #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,9 @@ func builtin_compile(self py.Object, args py.Tuple, kwargs py.StringDict) (py.Ob
return nil, py.ExceptionNewf(py.ValueError, "compile(): invalid optimize value")
}

if dont_inherit.(py.Int) != 0 {
// if dont_inherit.(py.Int) != 0 {
// PyEval_MergeCompilerFlags(&cf)
}
// }

// switch string(startstr.(py.String)) {
// case "exec":
Expand Down Expand Up @@ -882,9 +882,8 @@ or ... etc.
`

func isinstance(obj py.Object, classOrTuple py.Object) (py.Bool, error) {
switch classOrTuple.(type) {
switch class_tuple := classOrTuple.(type) {
case py.Tuple:
var class_tuple = classOrTuple.(py.Tuple)
for idx := range class_tuple {
res, _ := isinstance(obj, class_tuple[idx])
if res {
Expand Down
1 change: 0 additions & 1 deletion compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,6 @@ func (c *compiler) NameOp(name string, ctx ast.ExprContext) {
default:
panic("NameOp: ctx invalid for name variable")
}
break
}
if op == 0 {
panic("NameOp: Op not set")
Expand Down
2 changes: 1 addition & 1 deletion compile/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestLnotab(t *testing.T) {
},
} {
got := test.instrs.Lnotab()
if bytes.Compare(test.want, got) != 0 {
if !bytes.Equal(test.want, got) {
t.Errorf("%d: want %d got %d", i, test.want, got)
}
}
Expand Down
2 changes: 1 addition & 1 deletion marshal/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func ReadPyc(r io.Reader) (obj py.Object, err error) {
}
// FIXME do something with timestamp & length?
if header.Magic>>16 != 0x0a0d {
return nil, errors.New("Bad magic in .pyc file")
return nil, errors.New("bad magic in .pyc file")
}
// fmt.Printf("header = %v\n", header)
return ReadObject(r)
Expand Down
3 changes: 1 addition & 2 deletions parser/stringescape.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func DecodeEscape(in *bytes.Buffer, byteMode bool) (out *bytes.Buffer, err error
// Early exit if no escape sequences
// NB in.Bytes() is cheap
inBytes := in.Bytes()
if bytes.IndexRune(inBytes, '\\') < 0 {
if !bytes.ContainsRune(inBytes, '\\') {
return in, nil
}
out = new(bytes.Buffer)
Expand Down Expand Up @@ -135,7 +135,6 @@ func DecodeEscape(in *bytes.Buffer, byteMode bool) (out *bytes.Buffer, err error
ignoreEscape = true
default:
ignoreEscape = true
break
}
// ignore unrecognised escape
if ignoreEscape {
Expand Down
4 changes: 2 additions & 2 deletions py/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ func (a Bytes) M__le__(other Object) (Object, error) {

func (a Bytes) M__eq__(other Object) (Object, error) {
if b, ok := convertToBytes(other); ok {
return NewBool(bytes.Compare(a, b) == 0), nil
return NewBool(bytes.Equal(a, b)), nil
}
return NotImplemented, nil
}

func (a Bytes) M__ne__(other Object) (Object, error) {
if b, ok := convertToBytes(other); ok {
return NewBool(bytes.Compare(a, b) != 0), nil
return NewBool(!bytes.Equal(a, b)), nil
}
return NotImplemented, nil
}
Expand Down
2 changes: 1 addition & 1 deletion py/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const NAME_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvw
// all_name_chars(s): true iff all chars in s are valid NAME_CHARS
func all_name_chars(s String) bool {
for _, c := range s {
if strings.IndexRune(NAME_CHARS, c) < 0 {
if !strings.ContainsRune(NAME_CHARS, c) {
return false
}
}
Expand Down
3 changes: 2 additions & 1 deletion py/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ func (a Int) M__pos__() (Object, error) {

func (a Int) M__abs__() (Object, error) {
if a == IntMin {
// FIXME upconvert
abig, _ := ConvertToBigInt(a)
return abig.M__abs__()
}
if a < 0 {
return -a, nil
Expand Down
2 changes: 1 addition & 1 deletion py/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func newBoundMethod(name string, fn interface{}) (Object, error) {
return f(a, b, c)
}
default:
return nil, fmt.Errorf("Unknown bound method type for %q: %T", name, fn)
return nil, fmt.Errorf("unknown bound method type for %q: %T", name, fn)
}
return m, nil
}
Expand Down
1 change: 0 additions & 1 deletion py/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ func computeRangeLength(start, stop, step Int) Int {
if step > 0 {
lo = start
hi = stop
step = step
} else {
lo = stop
hi = start
Expand Down
5 changes: 2 additions & 3 deletions py/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ func StringEscape(a String, ascii bool) string {
func fieldsN(s string, n int) []string {
out := []string{}
cur := []rune{}
r := []rune(s)
for _, c := range r {
for _, c := range s {
//until we have covered the first N elements, multiple white-spaces are 'merged'
if n < 0 || len(out) < n {
if unicode.IsSpace(c) {
Expand Down Expand Up @@ -139,7 +138,7 @@ func init() {
maxSplit = int(m)
}
}
valArray := []string{}
var valArray []string
if valStr, ok := value.(String); ok {
valArray = strings.SplitN(string(selfStr), string(valStr), maxSplit+1)
} else if _, ok := value.(NoneType); ok {
Expand Down
6 changes: 3 additions & 3 deletions vm/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,9 @@ func do_IMPORT_NAME(vm *Vm, namei int32) error {
}
v := vm.POP()
u := vm.TOP()
var locals py.Object = vm.frame.Locals
if locals == nil {
locals = py.None
var locals py.Object = py.None
if vm.frame.Locals != nil {
locals = vm.frame.Locals
}
var args py.Tuple
if _, ok := u.(py.Int); ok {
Expand Down