-
Notifications
You must be signed in to change notification settings - Fork 556
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
Namespace unbind #1985
base: main
Are you sure you want to change the base?
Namespace unbind #1985
Conversation
Updates the requirements on [sphinx](https://github.com/sphinx-doc/sphinx) to permit the latest version. - [Release notes](https://github.com/sphinx-doc/sphinx/releases) - [Changelog](https://github.com/sphinx-doc/sphinx/blob/5.x/CHANGES) - [Commits](sphinx-doc/sphinx@v0.1.61611...v5.0.0) --- updated-dependencies: - dependency-name: sphinx dependency-type: direct:production ... Signed-off-by: dependabot[bot] <[email protected]>
Update sphinx requirement from <5 to <6
rdflib/plugins/stores/berkeleydb.py
Outdated
if prefix is None: | ||
return |
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.
As prefix should be supplied as a str
I think it is best to omit this custom handling, if anything it can maybe be a TypeError
, but I think avoiding custom handling for prefix is None
is best. If someone does it they can live with the consequences if it does not fail.
if prefix is None: | |
return |
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.
True, coherent type-hinting would resolve this more neatly and I was lazy.
My excuse is - that from a meta-perspective I'm not sure that this PR is desirable in that adding an explicit unbind
is arguably not worth the effort when the functionality already exists via bind(<prefix>, None)
From this perspective, it's more of a documentation / docstring issue.
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'm not sure that this PR is desirable in that adding an explicit
unbind
is arguably not worth the effort when the functionality already exists viabind(<prefix>, None)
From this perspective, it's more of a documentation / docstring issue.
If this is the case we can possibly implement this by checking if the underlying store implements unbind
, and if not call bind(, None)
- but I'm not sure if all stores will work with this either.
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.
If this is the case we can possibly implement this by checking if the underlying store implements
unbind
, and if not callbind(, None)
- but I'm not sure if all stores will work with this either.
Oh, looks like I was mistaken in believing that there was existing functionality for unbinding via binding to None
def test_extant_graph_unbind(tmp_path: Path, store_name: str) -> None:
graph = make_graph(tmp_path, store_name)
graph.bind("", EGNSSUB_V0)
check_ns(graph, {"": EGNSSUB_V0})
graph.bind("", None)
assert list(graph.namespaces()) == [
("", URIRef("http://example.com/sub/v0")),
("default1", URIRef("None")),
]
def test_extant_store_unbind(tmp_path: Path, store_name: str) -> None:
graph = make_graph(tmp_path, store_name)
graph.bind("", EGNSSUB_V0)
check_ns(graph, {"": EGNSSUB_V0})
graph.store.bind("", None)
if store_name == "BerkeleyDB":
assert list(graph.store.namespaces()) == [
("", URIRef("http://example.com/sub/v0"))
]
else:
assert list(graph.store.namespaces()) == [("", None)]
I guess that appreciably changes matters: the rebased PR is worth submitting, so coherent type-hinting it is then 😄
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.
Okay, I've added more type hinting (perhaps clumsily, it's not one of my strong points). Had to protect berkeleydb from trying to apply decode("utf-8)
to None
although the tests do show that mypy will report the type error.
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.
Okay, I've added more type hinting (perhaps clumsily, it's not one of my strong points).
Definitely not, sigh. Changed param namespace
type to str
throughout, reflecting contemporary usage, seems to satisfy everything except the Type[DOAP]
in test/util/earl.py
, so I've temporarily added type ignore to those. I guess URIRef
and Namespace
satisfy some behavioural criterion that allows them to be str
whereas Type
doesn't.
@gjhiggins the change looks good, I will think of ways which we can incorporate it into master and keep it there until we release version 7. I'm thinking we add That way we can run CI on them, and once we release version 7 we just change Would like to know what others think of this approach. CC: @mwatts15 |
…args both `bind` and `unbind` benefit from type-hinting
# Conflicts: # test/utils/earl.py
Summary of changes
Potentially API-breaking for external plugin stores. If accepted, schedule for inclusion in 7.0
Draft PR rebasing and extending PR #1094 to bring up to finalising accept/reject level (then it can be closed one way or the other)
Adds
unbind(prefix: str) -> None
method to Graph API, propagated downwards fromGraph
to individual store implementations (SimpleMemory
,Memory
,BerkeleyDB
, etc).Checklist
./examples
for new features. TBD if Draft approvedCHANGELOG.md
). TBD if Draft approvedso maintainers can fix minor issues and keep your PR up to date.