FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement set repr by xarus01 · Pull Request #117 · go-python/gpython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (8) .py  (1) .txt  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 2 additions & 2 deletions builtin/builtin.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func init() {
"object": py.ObjectType,
"range": py.RangeType,
// "reversed": py.ReversedType,
"set": py.SetType,
"slice": py.SliceType,
"set": py.SetType,
"slice": py.SliceType,
"staticmethod": py.StaticMethodType,
"str": py.StringType,
// "super": py.SuperType,
Expand Down
Empty file added coverage.txt
Empty file.
2 changes: 1 addition & 1 deletion parser/lexer_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func approxEq(a, b float64) bool {
log.Printf("ApproxEq(a = %#v, b = %#v)", a, b)
diff := a - b
log.Printf("ApproxEq(diff = %e)", diff)
if math.Abs(diff) > 1E-10 {
if math.Abs(diff) > 1e-10 {
log.Printf("ApproxEq(false)")
return false
}
Expand Down
7 changes: 3 additions & 4 deletions py/range.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ func computeRangeSlice(r *Range, s *Slice) (Object, error) {
sliceLength = computeRangeLength(startIndex, stopIndex, stepIndex)

return &Range{
Start: startIndex,
Stop: stopIndex,
Step: stepIndex,
Start: startIndex,
Stop: stopIndex,
Step: stepIndex,
Length: sliceLength,
}, nil
}
Expand All @@ -238,7 +238,6 @@ var _ I__getitem__ = (*Range)(nil)
var _ I__iter__ = (*Range)(nil)
var _ I_iterator = (*RangeIterator)(nil)


func (a *Range) M__eq__(other Object) (Object, error) {
b, ok := other.(*Range)
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion py/range_repr110.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ func (r *Range) repr() (Object, error) {
b.WriteString(")")

return String(b.String()), nil
}
}
2 changes: 1 addition & 1 deletion py/range_repr19.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ func (r *Range) repr() (Object, error) {
b.WriteString(")")

return String(b.String()), nil
}
}
21 changes: 21 additions & 0 deletions py/set.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package py

import "bytes"

var SetType = NewTypeX("set", "set() -> new empty set object\nset(iterable) -> new set object\n\nBuild an unordered collection of unique elements.", SetNew, nil)

type SetValue struct{}
Expand Down Expand Up @@ -102,6 +104,25 @@ func (s *Set) M__bool__() (Object, error) {
return NewBool(len(s.items) > 0), nil
}

func (s *Set) M__repr__() (Object, error) {
var out bytes.Buffer
out.WriteRune('{')
spacer := false
for item := range s.items {
if spacer {
out.WriteString(", ")
}
str, err := ReprAsString(item)
if err != nil {
return nil, err
}
out.WriteString(str)
spacer = true
}
out.WriteRune('}')
return String(out.String()), nil
}

func (s *Set) M__iter__() (Object, error) {
items := make(Tuple, 0, len(s.items))
for item := range s.items {
Expand Down
11 changes: 10 additions & 1 deletion py/tests/set.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@
d = a ^ b
assert 1 in c

doc="__repr__"
a = {1, 2, 3}
b = a.__repr__()
Comment thread
sbinet marked this conversation as resolved.
assert "{" in b
assert "1" in b
assert "2" in b
assert "3" in b
assert "}" in b

doc="set"
a = set([1,2,3])
b = set("set")
Expand Down Expand Up @@ -83,4 +92,4 @@
assert a.__eq__({1,2,3}) == True
assert a.__ne__({1,2,3}) == False

doc="finished"
doc="finished"
2 changes: 1 addition & 1 deletion symtable/symtable_data_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ var symtableTestData = []struct {
Children: Children{},
},
},
}, nil,""},
}, nil, ""},
{"def fn(a):\n global b\n global b\n return b", "exec", &SymTable{
Type: ModuleBlock,
Name: "top",
Expand Down
4 changes: 2 additions & 2 deletions time/time.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Return the current time in seconds since the Epoch.
Fractions of a second may be present if the system clock provides them.`

func time_time(self py.Object) (py.Object, error) {
return py.Float(time.Now().UnixNano()) / 1E9, nil
return py.Float(time.Now().UnixNano()) / 1e9, nil
}

// func floatclock(_Py_clock_info_t *info) (py.Object, error) {
Expand Down Expand Up @@ -141,7 +141,7 @@ func time_sleep(self py.Object, args py.Tuple) (py.Object, error) {
if secs < 0 {
return nil, py.ExceptionNewf(py.ValueError, "sleep length must be non-negative")
}
time.Sleep(time.Duration(secs * 1E9))
time.Sleep(time.Duration(secs * 1e9))
return py.None, nil
}

Expand Down

Back | FazBrowse Home | New Git URL