Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make XMLSyntaxError have normal SyntaxError metadata #217

Merged
merged 1 commit into from
Dec 6, 2016

Conversation

flying-sheep
Copy link
Contributor

@flying-sheep flying-sheep commented Dec 4, 2016

Some tools (e.g. IPython) show a special error message like the following if common SyntaxError metadata is available:

$ PYTHONPATH=src ipython
In [1]: from lxml import etree
In [2]: etree.parse('src/lxml/tests/test_broken.xml')
  File "src/lxml/tests/test_broken.xml", line 1
    <a><b></c></b></a>
             ^
XMLSyntaxError: Opening and ending tag mismatch: b line 1 and c, line 1, column 11

This PR adds the necessary fields filename, lineno and offset, while making position a property in order to keep it in sync with lineno and offset if those are changed.

self.assertEqual(e.lineno, 1)
self.assertEqual(e.offset, 10)
except Exception as e:
self.fail('{}, not {}'.format(fail_msg, type(e)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty format keys aren't supported in Py2.6.

@scoder
Copy link
Member

scoder commented Dec 6, 2016

Cool, really nice feature.

@scoder scoder merged commit 445762d into lxml:master Dec 6, 2016
@flying-sheep flying-sheep deleted the syntax-error-meta branch December 6, 2016 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants