Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upImplement floordiv and NotImplemented.__repr__() #270
Conversation
|
I know this is still a WIP, just thought I'd provide a few suggestions. |
| @@ -98,6 +98,22 @@ func intEq(f *Frame, v, w *Object) (*Object, *BaseException) { | |||
| return intCompare(compareOpEq, toIntUnsafe(v), w), nil | |||
| } | |||
|
|
|||
| func intFloorDiv(f *Frame, v, w *Object) (*Object, *BaseException) { | |||
| if !v.isInstance(IntType) { | |||
| return nil, f.RaiseType(TypeErrorType, fmt.Sprintf("descriptor '__floordiv__' requires a 'int' object but received a '%s'", v.typ.Name())) | |||
This comment has been minimized.
This comment has been minimized.
trotterdylan
Mar 22, 2017
Collaborator
The slot delegation code guarantees that the first argument to slot functions is of the correct type, so no need to check here.
| longDiv(z, x, y) | ||
| }) | ||
| } | ||
| fv, _ := intFloat(f, v) |
This comment has been minimized.
This comment has been minimized.
trotterdylan
Mar 22, 2017
Collaborator
You should be able to return NotImplemented in this case and it will delegate to w's operator.
| @@ -384,6 +400,7 @@ func initIntType(dict map[string]*Object) { | |||
| IntType.slots.Div = &binaryOpSlot{intDiv} | |||
| IntType.slots.DivMod = &binaryOpSlot{intDivMod} | |||
| IntType.slots.Eq = &binaryOpSlot{intEq} | |||
| IntType.slots.FloorDiv = &binaryOpSlot{intFloorDiv} | |||
This comment has been minimized.
This comment has been minimized.
trotterdylan
Mar 22, 2017
Collaborator
Thinking about it a little more, I think you can just use intDiv for this slot. I think it does exactly what you want.
| @@ -1,33 +1,405 @@ | |||
| def eq(a, b): | |||
| return a == b | |||
| """ | |||
This comment has been minimized.
This comment has been minimized.
|
@trotterdylan Thanks for the early review. I will change them as your comment. |
|
@trotterdylan Ready for review. PTAL |
|
This is great! Thanks for working on this. Just one question in line. |
| @@ -471,6 +473,11 @@ func intCheckedDiv(v, w int) (int, divModResult) { | |||
| return q, r | |||
| } | |||
|
|
|||
| func intCheckedFloorDiv(v, w int) (int, divModResult) { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
corona10
Mar 23, 2017
Author
Contributor
@trotterdylan
Not at all. Thanks, I didn't find that! I will update it
|
@trotterdylan PTAL |
|
Looks great! Thanks for working on this. Merging. |
53a6dfb
into
google:master

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

corona10 commentedMar 21, 2017
•
edited
This PR is related with #269