lxml/lxml — pull request #136 by muzhig (2014-03-21 12:58:15+00:00)
Title: Filling namespace of a newly created element if nsmap with default value is given (UT included)

To explain the issue I'll show is the code that speaks for itself

>>> element = etree.Element('sometag', nsmap={None: 'somenamespace'})
>>> element.tag
u'sometag'
>>> element2 = etree.fromstring(etree.tostring(element))
>>> element2.tag
u'{somenamespace}sometag'
>>> xsd = etree.fromstring("""

""")
>>> schema = etree.XMLSchema(xsd)
>>> schema.validate(element)
False
>>> schema.validate(element2)
True

This pull request has a really simple and obvious fix that removes this inconsistency of de/serialization and enables validation for newly created element objects with missing explicit namespace prefixes.

Unit tests are included.

Here is the description of the problem on StackOverflow: http://stackoverflow.com/questions/22535284/strange-lxml-behavior