Description
Reading an empty core-property date element raises TypeError, while a missing element or an invalid date string returns None.
This affects created, modified, and last_printed when a document contains an empty corresponding XML element.
Reproduction
from docx.opc.coreprops import CoreProperties
from docx.oxml.parser import parse_xml
xml = b'''<cp:coreProperties
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns:dcterms="http://purl.org/dc/terms/">
<dcterms:created/>
</cp:coreProperties>'''
print(CoreProperties(parse_xml(xml)).created)
Expected: None, consistent with the existing handling of absent or invalid dates.
Actual: TypeError: 'NoneType' object is not subscriptable in _parse_W3CDTF_to_datetime.
Reproduced on current master with Python 3.12. Regression cases fail for all three empty date elements; whitespace and invalid-string controls already pass. I can submit a small guard with these tests.
I checked the existing fractional-seconds PR #1608; it changes date parsing but does not handle empty elements, so this is a separate case.
AI assistance was used to investigate and test this report.
Description
Reading an empty core-property date element raises
TypeError, while a missing element or an invalid date string returnsNone.This affects
created,modified, andlast_printedwhen a document contains an empty corresponding XML element.Reproduction
Expected:
None, consistent with the existing handling of absent or invalid dates.Actual:
TypeError: 'NoneType' object is not subscriptablein_parse_W3CDTF_to_datetime.Reproduced on current
masterwith Python 3.12. Regression cases fail for all three empty date elements; whitespace and invalid-string controls already pass. I can submit a small guard with these tests.I checked the existing fractional-seconds PR #1608; it changes date parsing but does not handle empty elements, so this is a separate case.
AI assistance was used to investigate and test this report.