diff --git a/builtin/builtin.go b/builtin/builtin.go index 8f4ef674..a1e10126 100644 --- a/builtin/builtin.go +++ b/builtin/builtin.go @@ -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": @@ -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 { diff --git a/compile/compile.go b/compile/compile.go index dc8851cf..d0f59c45 100644 --- a/compile/compile.go +++ b/compile/compile.go @@ -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") diff --git a/compile/instructions_test.go b/compile/instructions_test.go index d5fecfed..01c7db4e 100644 --- a/compile/instructions_test.go +++ b/compile/instructions_test.go @@ -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) } } diff --git a/marshal/marshal.go b/marshal/marshal.go index dd039d5c..c29c97bf 100644 --- a/marshal/marshal.go +++ b/marshal/marshal.go @@ -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) diff --git a/parser/stringescape.go b/parser/stringescape.go index 5341ce44..c5c61ca3 100644 --- a/parser/stringescape.go +++ b/parser/stringescape.go @@ -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) @@ -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 { diff --git a/py/bytes.go b/py/bytes.go index b9ae3abe..2c653455 100644 --- a/py/bytes.go +++ b/py/bytes.go @@ -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 } diff --git a/py/code.go b/py/code.go index 355e88e0..09027497 100644 --- a/py/code.go +++ b/py/code.go @@ -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 } } diff --git a/py/int.go b/py/int.go index d9040fed..c183991d 100644 --- a/py/int.go +++ b/py/int.go @@ -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 diff --git a/py/method.go b/py/method.go index 1f8ecb72..28e8c1d5 100644 --- a/py/method.go +++ b/py/method.go @@ -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 } diff --git a/py/range.go b/py/range.go index 1f0513f8..1b261ccd 100644 --- a/py/range.go +++ b/py/range.go @@ -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 diff --git a/py/string.go b/py/string.go index b985621d..0f9ddc28 100644 --- a/py/string.go +++ b/py/string.go @@ -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) { @@ -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 { diff --git a/vm/eval.go b/vm/eval.go index e98392a9..f8e2ef8f 100644 --- a/vm/eval.go +++ b/vm/eval.go @@ -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 {
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: