rdflib icon indicating copy to clipboard operation
rdflib copied to clipboard

fix: handling of Literal datatype

Open aucampia opened this issue 2 years ago • 1 comments

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 be Optional[URIRef] instead of Optional[str] now that str will always be converted to URIRef 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 granting push permissions to the PR branch, so maintainers can fix minor issues and keep your PR up to date.

aucampia avatar Aug 07 '22 20:08 aucampia

Coverage Status

Coverage increased (+0.003%) to 90.451% when pulling f31625e3a2a125f3d9e9e3ec3468b772a7491be0 on aucampia:iwana-20220807T1740-datatype_uri into 131d9e66e8515aa81d776969d42f58c72bc68f86 on RDFLib:master.

coveralls avatar Aug 07 '22 20:08 coveralls