rdflib
rdflib copied to clipboard
fix: handling of Literal datatype
Summary of changes
Check datatype against None
instead of checking it's truthiness (i.e.
if datatype is not None:
instead of if datatype:
).
Checking truthiness instead of is not None
causes a blank string to
be treated the same as None. The consequence of this was that
Literal.datatype
could be a str
, a URIRef
or None
, instead of
just a URIRef
or None
as was seemingly intended.
Other changes:
- Changed the type of
Literal.datatype
to beOptional[URIRef]
instead ofOptional[str]
now thatstr
will always be converted toURIRef
even if it is a blank string. - Changed
rdflib.util._coalesce
to make it easier and safer to use with a non-None
default value. - Added
rdflib.util._convert_optional
that makes it easy to convert optional values while retaining their optional nature. - Changed
rdflib.util
to avoid issues with circular imports.
Checklist
- [x] Checked that there aren't other open pull requests for the same change.
- [x] Added tests for any changes that have a runtime impact.
- [x] Checked that all tests and type checking passes.
- For changes that have a potential impact on users of this project:
- [x] Considered updating our changelog (
CHANGELOG.md
).
- [x] Considered updating our changelog (
- [x] Considered granting push permissions to the PR branch, so maintainers can fix minor issues and keep your PR up to date.