fix: remove Literal.toPython date conversion for gYear/gYearMonth #3115
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
Issue #3078 reports, that
rdflib.Literal.toPython
-casting ofxsd:gYear
andxsd:gYearMonth
to datetime objects should not be possible, as there is no appropriate Python equivalence for those types.The current implementation casts
xsd:gYear
andxsd:gYearMonth
to datetime objects assuming January 1st forxsd:gYear
and the 1st day of the given month forxsd:gYearMonth
. This is plain wrong.The change removes datetime casting for
xsd:gYear
andxsd:gYearMonth
forrdflib.Literal.toPython
and adapts therdflib.Literal
tests accordingly.Note that validation of
xsd:gYear
andxsd:gYearMonth
is lost as a result, but could be easily implemented using regex checks. As I understand it, XSD types without an entry in therdflib.term.XSDToPython
mapping are never typed-checked though; at least forxsd:gYear
andxsd:gYearMonth
the xsd-type checks ran as part ofrdflib.xsd_datetime.parse_xsd_gyear
andrdflib.xsd_datetime.parse_xsd_gyearmonth
.Checklist
the same change.
./examples
.so maintainers can fix minor issues and keep your PR up to date.
Note: I looked through the docs and couldn't find a place where
xsd:gYear
orxsd:gYearMonth
casting was mentioned (apart from the generated references).