-
Notifications
You must be signed in to change notification settings - Fork 95
Initial work at implementing file methods #13
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #13 +/- ##
==========================================
+ Coverage 64.48% 64.59% +0.11%
==========================================
Files 55 55
Lines 9821 9997 +176
==========================================
+ Hits 6333 6458 +125
- Misses 3039 3079 +40
- Partials 449 460 +11
Continue to review full report at Codecov.
|
That looks very good :-) Can you write some unit tests? These are written in python normally. I'd suggest you make a new file Not sure exactly what to do about test files - that might need a bit of thought. |
Sure, will do! |
retest |
Do you know why the build is failing now ? In one place is complaining about gcc missing, and in the other it's failing compiling with Go 1.8 (but doesn't look it's in my code) |
Yes, it's appveyor.yml issue. |
@raff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work!
I have a couple of comments and suggestions.
builtin/builtin.go
Outdated
preferred way to open a file. See file.__doc__ for further information.` | ||
|
||
func builtin_open(self, obj py.Object) (py.Object, error) { | ||
if filename, ok := obj.(py.String); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please always strive to limit indentation.
e.g.:
if filename, ok := obj.(py.String); ok {
return py.OpenFile(string(filename))
}
return nil, py.ExceptionNewf(py.TypeError, "coercing to Unicode: need string or buffer, %v found", obj.Type().Name)
py/file.go
Outdated
type File os.File | ||
|
||
var FileType = NewType("file", `represents an open file`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please document this exported variable.
actually.. do we need it to be exported, at this time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I copied what one of the other module did and tried to follow the same pattern. Happy to update to a more gopheric style if one is defined.
But I agree that in the current implementation there are a lot of objects that are exported and maybe don't really need to be.
py/file.go
Outdated
} | ||
|
||
func (o *File) readResult(b []byte) (Object, error) { | ||
var asBytes = false // default mode is "as string" - also move this in File struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we could already do that as part of this CL ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have this part done (but I am still not done parsing the options for open() so it would still just work for string output).
Found some problems in the option parser that I am trying to decide if I want to ignore them for now or trying to get them fixed.
py/file.go
Outdated
var asBytes = false // default mode is "as string" - also move this in File struct | ||
|
||
if b == nil { | ||
if asBytes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please prefer early returns to limit the needed amount of indentation.
py/file.go
Outdated
|
||
if asBytes { | ||
return Bytes(b), nil | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please prefer early returns to limit the needed amount of indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbinet At some point we should be running golint which warns about this. However there is a lot of stuff to fix if we do decide to implement it!
Finished up (for now) open file and rebased. |
Please squash into the single commit please |
@@ -12,8 +12,10 @@ import ( | |||
"testing" | |||
|
|||
_ "github.com/go-python/gpython/builtin" | |||
_ "github.com/go-python/gpython/sys" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to duplicate the "sys" import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that is looking good :-)
One small thing to change inline, then if you could squash and rebase on master that would be perfect - thanks
After rebasing a million times (and maybe now I have finally figured out how to do it right) I think I am done! |
builtin/builtin.go
Outdated
} | ||
|
||
if newline != py.None { | ||
return nil, py.ExceptionNewf(py.NotImplementedError, "errors not implemented yet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be like this?
return nil, py.ExceptionNewf(py.NotImplementedError, "newline not implemented yet")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
- open (builtin) - File.read - File.write - File.close
LGTM, Let's wait for @ncw review :) |
Notes for future work... It would be nice to improve the coverage of file.go. Ideally what we need are tests which exercise the expected functionality of The args.go file doesn't have any tests which is a bit sad :-( |
Initial work at implementing file methods: