-
Notifications
You must be signed in to change notification settings - Fork 560
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
Incongruity in type signature of NamespaceManager #2004
Comments
@ajnelson-nist that is in primarily because it will return URIRef objects and not Namespace objects: From monkeytype: 20220729T042949 [email protected]:~/sw/d/github.com/iafork/rdflib.monkeytype
$ task run -- monkeytype stub rdflib.namespace | tee rdflib/namespace/__init__.pyi
task: [run]
VIRTUAL_ENV="/home/iwana/sw/d/github.com/iafork/rdflib.monkeytype/.venv" PATH="/home/iwana/sw/d/github.com/iafork/rdflib.monkeytype/.venv/bin${PATH: :${PATH}}" monkeytype stub rdflib.namespace
55 traces failed to decode; use -v for details
from rdflib.term import URIRef
from typing import (
Any,
Dict,
Iterable,
List,
Optional,
Tuple,
Type,
Union,
)
# ...elided...
class NamespaceManager:
def __init__(self, graph: Graph, bind_namespaces: _NamespaceSetString = ...) -> None: ...
def _store_bind(self, prefix: str, namespace: URIRef, override: bool) -> None: ...
def absolutize(self, uri: str, defrag: int = ...) -> URIRef: ...
def bind(self, prefix: Optional[str], namespace: Any, override: bool = ..., replace: bool = ...) -> None: ...
def compute_qname(self, uri: str, generate: bool = ...) -> Tuple[str, URIRef, str]: ...
def compute_qname_strict(self, uri: str, generate: bool = ...) -> Tuple[str, str, str]: ...
def expand_curie(self, curie: str) -> Optional[URIRef]: ...
def namespaces(self) -> Iterable[Tuple[str, URIRef]]: ...
def normalizeUri(self, rdfTerm: str) -> str: ...
def qname(self, uri: str) -> str: ...
def qname_strict(self, uri: str) -> str: ...
def reset(self) -> None: ...
@property
def store(self) -> Store: ...
# ...elided... And from pytest-annotate {
"path": "rdflib/namespace/__init__.py",
"line": 707,
"func_name": "NamespaceManager.namespaces",
"type_comments": [
"() -> Iterator",
"() -> Iterator[Tuple[str, rdflib.term.URIRef]]"
],
"samples": 2051
},
|
@aucampia That is an informative view of the inertia of that type signature. However, I believe there are good reasons to upset it. In particular, I'm concerned with the interface between the I personally expect I've seen significant confusion arise from these concepts being muddied, some back since the pre-RDF days of XML:
Each of these is still a distinct concept. Some current technologies make confusions of them all come data-serialization time. FOAF ends its ontology IRI with a slash, which OWL permits and which allows a handy and inoffensive confusion of ontology IRI, namespace, and string prefix. But I'm particularly thinking of JSON-LD's context dictionary that uses string prefixes, which are not necessarily namespaces. I encountered this when dealing with the differences in forward-slash parsing between SPARQL, Turtle, and JSON-LD to handle IANA Media types and their slashes. (IANA Media Types don't have an IANA-provide ontology to my knowledge, but Dublin Core Terms provides http://purl.org/dc/terms/IMT, and a "namespace for MIME media types vocabulary" from the Publishing Metadata documnt: So, I wish to argue for precision in the type designation for If you agree with this way forward, I will put some effort into the type designation with a PR. |
Store, NamespaceManager and Graph will have more or less complete type signatures with #2080 - the type signature for Lines 1191 to 1197 in 97f88d3
In here, the namespace has type Currently we have namespaces occurring with the following types:
The class diagram for these types is: If not for However, all these classes do have rdflib/rdflib/namespace/__init__.py Lines 639 to 655 in 97f88d3
So really, anything can be passed as the But this is also why the the following three methods return
If you pass a rdflib/rdflib/plugins/stores/berkeleydb.py Lines 587 to 598 in 97f88d3
It would be better if rdflib/rdflib/namespace/__init__.py Line 655 in 97f88d3
to something like namespace = Namespace(str(namespace)) (and some additional changes) We should look at doing this in a future version of RDFLib, however we need quite a big overhaul of our public interfaces in general, as shared in some other places, I think the right approach here is that we should design a new Graph interface addressing most of the problems that we know of in We should also really have architectural decision records for interface breakages, and ideally there should be a deprecation notice or warning in at least one version with some option for adopting the new behaviour. |
I had a sneaking feeling there would be some reason due to technology breadth. Thanks to your thorough explanation---and thanks for it!---I agree with this needing to be in a 7.0.0 release. Is there a development branch where such effects are being pooled, or is there some new module |
I will try to find time to make an ADR this weekend to define But even with this we should be as conservative as possible with interface breakages, one other option here is to change Namespace and DefinedNamespace to inherit from URIRef, and then we can actually change the code just fine without breaking interfaces. Ideally there should be issues for all problems with the existing interfaces, and most of them should be labelled as |
Is there a reason
rdflib.namespace.NamespaceManager.namespaces
has the return signatureIterable[Tuple[str, URIRef]]
- specifically,URIRef
instead ofNamespace
?The text was updated successfully, but these errors were encountered: