-
Notifications
You must be signed in to change notification settings - Fork 578
Apply IdentifiedNode to Graph iterators #1697
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
Apply IdentifiedNode to Graph iterators #1697
Conversation
This patch is known to be incomplete with respect to other needed revisions to type signatures, both in Graph subclasses and in graph consumers elsewhere under `/rdflib`. However, running this change through a type checker raised some questions on `Node` specificity and circular type dependencies, and so is posted for discussion. References: * RDFLib#1696 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
This resolves type signature issues raised in the prior patch, but might require a follow-on patch depending on `Path` discussion. References: * RDFLib#1696 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
This resolves type signature issues raised in the prior patch, but might require a follow-on patch depending on `Path` discussion. References: * RDFLib#1696 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
This patch makes no semantic changes, instead applying formatting from `black`. Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
This is ready for look-overs. Let's keep discussion to #1696. |
Thanks to Iwan for noting this variable's behavior. References: * RDFLib#1696 Reported-by: Iwan Aucamp <aucampia@gmail.com> Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
References: * RDFLib#1696 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
`mypy` was confused by some of the variable name re-use and/or re-definition. This patch also highlights that `Path`s can be yielded in the predicate position, which has further downstream consequences in `graph.py` and in the `Store` class. References: * RDFLib#1696 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
I will have a look later this week, but this is quite critical to do, so thanks. I will also see if I can make CI pipeline pass. |
self, | ||
triple: Tuple[ | ||
Optional[IdentifiedNode], Union[None, Path, IdentifiedNode], Optional[Node] | ||
], | ||
) -> Iterable[Tuple[IdentifiedNode, Union[IdentifiedNode, Path], Node]]: |
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 this is more correct than it was, but technically this should be:
self, | |
triple: Tuple[ | |
Optional[IdentifiedNode], Union[None, Path, IdentifiedNode], Optional[Node] | |
], | |
) -> Iterable[Tuple[IdentifiedNode, Union[IdentifiedNode, Path], Node]]: | |
self, | |
triple: Tuple[ | |
Optional[IdentifiedNode], Union[None, Path, URIRef], Optional[Node] | |
], | |
) -> Iterable[Tuple[IdentifiedNode, Union[URIRef, Path], Node]]: |
Fine with it as is though, we can narrow it more later, this narrow already makes things better.
Same applies other in places also, won't label them all, just a note.
Type checking passes now. I also included some changes which reduces the footprint of this change so that it becomes almost entirely just change of type annotations. This may be a bit on the pendatic side, and I would be fine if you keep the changes as they were, but I would rather keep refactoring seperate from changes to add typing.
Change looks very good, thanks, and it is quite essential, I made some minor fixes in ajnelson-nist#14 to get the type checking to pass, and I also roll back some changes which is not entirely essential for this PR's aim, but it's up to you what to do with those. |
…de_changes Fix type checking errors
For some reason mypy does not complain about unused ignores on my computer, will have to figure out why, but I removed the ignores that are not needed now and type validation seems to pass. |
Thanks! I just hit that too, and I'm dealing with a weirdness in
Partially reverting your PR to split that up again is...almost helping. I'm close to pushing a patch once I figure out the spirit of the |
This validates on github actions now, I think maybe I have an older version of mypy than is being used on github actions |
Hm, seems I had an old-mypy issue too. I was on 0.920, upgraded to 0.931, and now that curious issue with I'm going to take this PR out of Draft mode now. It seems ready for any last review and merge to me. |
...I spoke a little soon, I missed |
pre-commit.ci autofix |
for more information, see https://pre-commit.ci
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 looks good to me, thanks again @ajnelson-nist
This only changes type annotations with one small exception, which is a change in variable names in well tested code path, this change in variable names is needed for type checking to pass without error/ignores as mypy does not like that the same variable has different types in the same scope:
Lines 495 to 497 in 06feef0
else: | |
for (_s, _p, _o), cg in self.__store.triples((s, p, o), context=self): | |
yield _s, _p, _o |
This PR also narrows some type annotations, but this narrowing brings things more in line with RDF 1.1 spec so I think it is good, if someone wants to use rdflib with non compliant types and type checking they will have to use # type: ignore
or cast
- but on the other hand, if we try and cater for non compliant RDF it also makes our lives harder.
The narrower types should however help users of this library detect errors in their code where they are potentially creating invalid RDF graphs.
I will add a page in docs regarding type annotations which covers some of the questions in #1696 and #1447
Fixes #1696
Proposed Changes
IdentifiedNode
onGraph.triples()
and related methodscompare.py
andrdf-xml
serializer.Note the
Graph
signature updates should also be propagated toGraph
subclasses before this is merged.