classification
Title: miniDOM._write_data() give a vague error message when the argument isn't of type str
Type: behavior Stage: resolved
Components: XML Versions: Python 3.6, Python 3.3, Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, oz.tamir, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2015-05-28 07:46 by oz.tamir, last changed 2015-05-28 15:14 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
issue24312.patch oz.tamir, 2015-05-28 07:49 review
Messages (4)
msg244283 - (view) Author: Oz Tamir (oz.tamir) Date: 2015-05-28 07:46
In Python 3.3, 3.4 and on 3.6.0a0 (default:dfe62f685538) the following snippet:

>>> from xml.dom.minidom import getDOMImplementation
>>> doc = getDOMImplementation().createDocument(None, 'Issues Tracker', None)
>>> tracker = doc.documentElement
>>> new_issue = doc.createElement('issue')
>>> new_issue.setAttribute('id', 10)
>>> tracker.appendChild(new_issue)
>>> with open('file.xml', 'w') as f:
...     doc.writexml(f, addindent='\t', newl='\n')


will produce the following exception:
[Traceback]
AttributeError: 'int' object has no attribute 'replace'

which I found to be vague and rather confusing.
msg244284 - (view) Author: Oz Tamir (oz.tamir) Date: 2015-05-28 07:49
I created a patch that will raise a TypeError when _write_data() has recvived an argument that is not a str.

I found this exception and the error message it provide to be more straight forward and helpful when encountering this error.
msg244300 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2015-05-28 14:16
As a rule, we don't put in checks like this. There are an untold number of places where such checks could be added. I suspect the new typing module will be a better way to catch these types of errors.

Does the problem not occur with 3.5?
msg244306 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-28 15:14
Agree with Eric. And the error message doesn't look lying.
History
Date User Action Args
2015-05-28 15:14:01serhiy.storchakasetstatus: open -> closed

nosy: + serhiy.storchaka
messages: + msg244306

resolution: rejected
stage: resolved
2015-05-28 14:16:16eric.smithsetnosy: + eric.smith
messages: + msg244300
2015-05-28 07:49:50oz.tamirsetfiles: + issue24312.patch
keywords: + patch
messages: + msg244284
2015-05-28 07:46:12oz.tamircreate