diff --git a/untangle.py b/untangle.py
index 1263056..6d1e966 100755
--- a/untangle.py
+++ b/untangle.py
@@ -14,6 +14,7 @@
  License: MIT License - http://www.opensource.org/licenses/mit-license.php
 """
 import os
+import keyword
 from xml.sax import make_parser, handler
 try:
     from StringIO import StringIO
@@ -133,6 +134,11 @@ class Handler(handler.ContentHandler):
         name = name.replace('-', '_')
         name = name.replace('.', '_')
         name = name.replace(':', '_')
+
+        # adding trailing _ for keywords
+        if keyword.iskeyword(name):
+            name += '_'
+
         attrs = dict()
         for k, v in attributes.items():
             attrs[k] = v

If an XML tag is a Python keyword SyntaxError is raised on access
Namely, I had this issue with a class tag.

My first thought is to use aliases for these.
diff --git a/tests/tests.py b/tests/tests.py
index 76a1ef4..33558e3 100755
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -93,6 +93,14 @@ class FromStringTestCase(unittest.TestCase):
 
         self.assertEqual('child1', getattr(o.root, 'child')[0]['name'])
 
+    def test_python_keyword(self):
+        o = untangle.parse("<class><return/><pass/><None/></class>")
+        self.assert_(o is not None)
+        self.assert_(o.class_ is not None)
+        self.assert_(o.class_.return_ is not None)
+        self.assert_(o.class_.pass_ is not None)
+        self.assert_(o.class_.None_ is not None)
+
 
 class InvalidTestCase(unittest.TestCase):
     """ Test corner cases """

pip install -e .[dev]
parse_log_pytest
pytest
pytest
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs @ file:///opt/conda/conda-bld/attrs_1642510447205/work
certifi==2021.5.30
importlib-metadata @ file:///tmp/build/80754af9/importlib-metadata_1631916693255/work
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work
packaging @ file:///tmp/build/80754af9/packaging_1637314298585/work
pluggy @ file:///tmp/build/80754af9/pluggy_1615976315926/work
py @ file:///opt/conda/conda-bld/py_1644396412707/work
pyparsing @ file:///tmp/build/80754af9/pyparsing_1635766073266/work
pytest==6.2.4
toml @ file:///tmp/build/80754af9/toml_1616166611790/work
typing_extensions @ file:///opt/conda/conda-bld/typing_extensions_1647553014482/work
-e git+https://github.com/stchris/untangle.git@2119763f721b23588b6223f28264843f6fc9f750#egg=untangle
zipp @ file:///tmp/build/80754af9/zipp_1633618647012/work

name: untangle
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - attrs=21.4.0=pyhd3eb1b0_0
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - importlib-metadata=4.8.1=py36h06a4308_0
  - importlib_metadata=4.8.1=hd3eb1b0_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - more-itertools=8.12.0=pyhd3eb1b0_0
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - packaging=21.3=pyhd3eb1b0_0
  - pip=21.2.2=py36h06a4308_0
  - pluggy=0.13.1=py36h06a4308_0
  - py=1.11.0=pyhd3eb1b0_0
  - pyparsing=3.0.4=pyhd3eb1b0_0
  - pytest=6.2.4=py36h06a4308_2
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - toml=0.10.2=pyhd3eb1b0_0
  - typing_extensions=4.1.1=pyh06a4308_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zipp=3.6.0=pyhd3eb1b0_0
  - zlib=1.2.13=h5eee18b_1
prefix: /opt/conda/envs/untangle

tests/tests.py::FromStringTestCase::test_python_keyword
tests/tests.py::FromStringTestCase::test_attribute_protocol tests/tests.py::FromStringTestCase::test_basic tests/tests.py::FromStringTestCase::test_basic_with_decl tests/tests.py::FromStringTestCase::test_grouping tests/tests.py::FromStringTestCase::test_single_root tests/tests.py::FromStringTestCase::test_with_attributes tests/tests.py::InvalidTestCase::test_empty_xml tests/tests.py::InvalidTestCase::test_invalid_xml tests/tests.py::InvalidTestCase::test_none_xml tests/tests.py::PomXmlTestCase::test_lengths tests/tests.py::PomXmlTestCase::test_parent tests/tests.py::NamespaceTestCase::test_namespace tests/tests.py::IterationTestCase::test_multiple_children tests/tests.py::IterationTestCase::test_single_child tests/tests.py::TwimlTestCase::test_twiml_dir tests/tests.py::UnicodeTestCase::test_lengths tests/tests.py::UnicodeTestCase::test_unicode_file tests/tests.py::UnicodeTestCase::test_unicode_string tests/tests.py::FileObjects::test_file_object tests/tests.py::UntangleInObjectsTestCase::test_object tests/tests.py::UrlStringTestCase::test_is_url tests/tests.py::TestSaxHandler::test_cdata tests/tests.py::TestSaxHandler::test_empty_handler tests/tests.py::TestSaxHandler::test_handler tests/tests.py::FigsTestCase::test_figs tests/tests.py::ParserFeatureTestCase::test_invalid_external_dtd tests/tests.py::ParserFeatureTestCase::test_invalid_feature tests/tests.py::ParserFeatureTestCase::test_valid_feature
untangle.py
untangle.py