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

Add support for print to file and file flush. by raff · Pull Request #27 · go-python/gpython · GitHub

Add support for print to file and file flush. - #27

Merged
ncw merged 1 commit into
go-python:masterfrom
raff:print_to_file
Sep 12, 2018
Merged

Add support for print to file and file flush.#27
ncw merged 1 commit into
go-python:masterfrom
raff:print_to_file

Conversation

raff commented Sep 8, 2018

Copy link
Copy Markdown
Contributor

No description provided.

codecov-io commented Sep 8, 2018
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #27 into master will increase coverage by 0.18%.
The diff coverage is 59.45%.

@@            Coverage Diff             @@
##           master      #27      +/-   ##
==========================================
+ Coverage   64.67%   64.86%   +0.18%     
==========================================
  Files          55       55              
  Lines       10044    10074      +30     
==========================================
+ Hits         6496     6534      +38     
+ Misses       3090     3079      -11     
- Partials      458      461       +3
Impacted Files Coverage Δ
py/file.go 53.14% <55%> (+2.35%) ⬆️
builtin/builtin.go 78.67% <64.7%> (+3.85%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cee534...faf6c54. Read the comment docs.

raff force-pushed the print_to_file branch 2 times, most recently from fb4a4f2 to d8a60c1 Compare September 10, 2018 18:58

ncw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks really good - thank you. Great to have the print working properly.

A few little things inline and a a few queries.

Comment thread builtin/builtin.go Outdated
return nil, err
}

// FIXME ignoring file and flush

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This comment is now out of date :-)

Comment thread builtin/builtin.go Outdated
if shouldFlush, _ := py.MakeBool(flush); shouldFlush == py.True {
fflush, err := py.GetAttrString(file, "flush")
if err == nil {
py.Call(fflush, nil, nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This should be returning an error on failure I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll see if I can reproduce a flush error in python 3 and fix if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added check for "file already closed". I don't think flush can return any other error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'd say we should as a matter of course return all the errors otherwise tools like errcheck (which I plan to run the codebase through) will complain that we aren't handling errors properly.

The error may need translating, that is for sure, but I think we should always return all errors!

Maybe we should make a generic error translator rather like the one here (from the open code)

        if err != nil {
                // XXX: should check for different types of errors
                switch {
                case os.IsExist(err):
                        return nil, ExceptionNewf(FileExistsError, err.Error())

                case os.IsNotExist(err):
                        return nil, ExceptionNewf(FileNotFoundError, err.Error())
                }
        }

(Note that this particular bit of code is ignoring the err if it wasn't one of those two errors which it shouldn't be - that needs to be fixed)

Comment thread py/file.go Outdated
}

func (o *File) Flush() (Object, error) {
_ = o.File.Sync()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe this should return None, o.File.Sync() otherwise we are ignoring the error on Sync()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll see if I can reproduce a flush error in python 3 and fix if needed.

Comment thread py/file.go Outdated

func (o *File) M__exit__(exc_type, exc_value, traceback Object) (Object, error) {
o.Close()
return None, nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Likewise here, return None, o.Close()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

o.Close() always return None - python File.close() never return an error.

Comment thread py/file.go Outdated
// Check interface is satisfied
var _ I__enter__ = (*File)(nil)
var _ I__exit__ = (*File)(nil)
var _ I__exit__ = (*File)(nil)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Duplicated __exit__ check?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sorry, I'll fix it.

raff force-pushed the print_to_file branch 2 times, most recently from e5b841e to 24e39a3 Compare September 11, 2018 15:59

raff commented Sep 11, 2018

Copy link
Copy Markdown
Contributor Author

Now all failed calls should properly return an error

ncw commented Sep 12, 2018

Copy link
Copy Markdown
Collaborator

This looks great now thanks. Will merge :-)

ncw merged commit 4f66e54 into go-python:master Sep 12, 2018
raff deleted the print_to_file branch October 4, 2018 20:20
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL