-
Notifications
You must be signed in to change notification settings - Fork 565
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
Make graph and other methods chainable #1394
Conversation
@wssbck this change might only need a few test changes for it to pass. I guess that, since most of the methods like Are you still keen to see this PR through? |
@nicholascar I would like to continue, yes. I got distracted by, well, life. |
@nicholascar I added returns to more methods and adjusted all the tests. I hope I have not missed anything. The build is passing now. |
@wssbck thanks for updating this PR. I'm happy that it's now doing what you want it to do and that it's passing tests however I want to check one thing with my co-maintainers still: @ashleysommer @white-gecko: this PR makes
|
Good question regarding performance. I don't think it will change anything, but I'll do a couple of benchmarks and get a number to compare. |
Ok, I created this simple benchmark (its a simple python method benchmark, not an rdflib benchmark): Conclusion: zero performance difference when returning |
@nicholascar this PR changes return values of several methods from implicit The practical effect is that these methods can now be chained, potentially making some downstream code more compact. Since the return values are now explicit, they are easier to reason about. It is, to my experience, always better to try to explicitly return something related to (or convenient because of) the purpose of the function/method rather than rely on the default behaviour of the language. |
Thanks @ashleysommer, I'll add you to formally review then and we are good to merge |
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.
Looks good
Since @ashleysommer's comment has been addressed, I'm merging |
@wssbck you might like to update the rdflib documentation files with a new PR to show chained use in action |
I will try to find time shortly, thanks for reviewing and merging! |
I was looking at fixing type checking, since I had some issues using 6.0.0 in typed python, and noticed that serialize will now sometimes return Just a note, I will fix the typing to correspond with what things are now, and then hopefully with type checking enabled in CI issues like this will be easier to spot. |
Doesn't serialize return a string/bytes, e.g. https://github.com/RDFLib/rdflib/blob/master/rdflib/graph.py#L1013 & https://github.com/RDFLib/rdflib/blob/master/rdflib/graph.py#L1033?
As above, when would serlialize() return None? Do you perhaps mean something like add()? That might return self/None and it was the focus of this PR more than serialize(). Just trying to make sure I understand the point!
Great, please do and I'll happily assist |
Other changes: - fix return value for `Graph.serialize` (refs RDFLib#1394) - remove default value for `rdflib.plugins.sparql.algebra.translateAlgebra` (refs RDFLib#1322) - add .dockerignore to reduce context size and make docker quicker to run. - add .flake8 config to ignore line length as black is managing formatting. - add mypy to docker-compose, makefile and tox.ini - fix the way csv2rdf is invoked to ensure that the right code gets executed.
Other changes: - fix return value for `Graph.serialize` (refs RDFLib#1394) - remove default value for `rdflib.plugins.sparql.algebra.translateAlgebra` (refs RDFLib#1322) - add .dockerignore to reduce context size and make docker quicker to run. - add .flake8 config to ignore line length as black is managing formatting. - add mypy to docker-compose, makefile and tox.ini - fix the way csv2rdf is invoked to ensure that the right code gets executed.
Other changes: - fix return value for `Graph.serialize` (refs RDFLib#1394) - remove default value for `rdflib.plugins.sparql.algebra.translateAlgebra` (refs RDFLib#1322) - add .dockerignore to reduce context size and make docker quicker to run. - add .flake8 config to ignore line length as black is managing formatting. - add mypy to docker-compose, makefile and tox.ini - fix the way csv2rdf is invoked to ensure that the right code gets executed.
Fixes RDFLib#1311 Add `mypy` to .drone.yml and fix type errors that come up. Not type checking examples or tests. Other changes: - fix return value for `Graph.serialize` (refs RDFLib#1394) - remove default value for `rdflib.plugins.sparql.algebra.translateAlgebra` (refs RDFLib#1322) - add .dockerignore to reduce context size and make docker quicker to run. - add .flake8 config to ignore line length as black is managing formatting. - add mypy to docker-compose, makefile and tox.ini - fix the way csv2rdf is invoked to ensure that the right code gets executed.
@nicholascar This change makes However if a destination is supplied and it is a network location I am actually unsure if this make sense, maybe this should rather raise a |
@aucampia ok, thanks for that explanation. I think you're right: always return the same thing ( I think you've already made a PR for this! But you have the network file location error as a warning not an error?? |
@nicholascar I only thought that throwing maybe better than logging a warning after I wrote the code for #1407. I updated the PR now to make |
Proposed Changes
Makes certain graph methods, like
remove
oradd
chainable. This will make it possible to write more concise code involving multiple graph modifications, along the lines of: