Skip to content

DeprecationWarning: Testing an XML element's truth value will raise an exception in future versions #1355

Closed

Description

@pawamoy

From a pytest run:

              last_child = self.lastChild(sibling)
              indent = 0
  >           while last_child:
  E           DeprecationWarning: Testing an element's truth value will raise an exception in future versions.  Use specific 'len(elem)' or 'elem is not None' test instead.

  __pypackages__/3.12/lib/markdown/extensions/admonition.py:79: DeprecationWarning

From https://docs.python.org/3.12/whatsnew/3.12.html#deprecated:

The xml.etree.ElementTree module now emits DeprecationWarning when testing the truth value of an xml.etree.ElementTree.Element. Before, the Python implementation emitted FutureWarning, and the C implementation emitted nothing.

Also from https://docs.python.org/3.12/whatsnew/3.12.html#pending-removal-in-python-3-14:

Testing the truth value of an xml.etree.ElementTree.Element is deprecated and will raise an exception in Python 3.14.

Python Markdown version: 3.3.7.

Not sure if this is fixed in later versions.

Activity

  1. facelessuser commented on Jul 17, 2023

    @facelessuser
    Collaborator

    I may pull the latest and run the tests on 3.12 and fix related issues. I'll assign this to me for now.

  2. self-assigned this
    on Jul 17, 2023
  3. facelessuser commented on Jul 17, 2023

    @facelessuser
    Collaborator

    We do have some issues which I've fixed locally:

    diff --git a/markdown/extensions/admonition.py b/markdown/extensions/admonition.py
    index 6d395f3..ce8492f 100644
    --- a/markdown/extensions/admonition.py
    +++ b/markdown/extensions/admonition.py
    @@ -78,14 +78,14 @@ class AdmonitionProcessor(BlockProcessor):
                 indent = 0
                 while last_child is not None:
                     if (
    -                    sibling and block.startswith(' ' * self.tab_length * 2) and
    -                    last_child and last_child.tag in ('ul', 'ol', 'dl')
    +                    sibling is not None and block.startswith(' ' * self.tab_length * 2) and
    +                    last_child is not None and last_child.tag in ('ul', 'ol', 'dl')
                     ):
     
                         # The expectation is that we'll find an `<li>` or `<dt>`.
                         # We should get its last child as well.
                         sibling = self.lastChild(last_child)
    -                    last_child = self.lastChild(sibling) if sibling else None
    +                    last_child = self.lastChild(sibling) if sibling is not None else None
     
                         # Context has been lost at this point, so we must adjust the
                         # text's indentation level so it will be evaluated correctly

    But we are also getting:

    Traceback (most recent call last):
      File "/Users/facelessuser/Code/github/markdown/tests/test_meta.py", line 20, in test__version__IsValid
        import packaging.version
    ModuleNotFoundError: No module named 'packaging'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/facelessuser/Code/github/markdown/tests/test_meta.py", line 22, in test__version__IsValid
        from pkg_resources.extern import packaging
    ModuleNotFoundError: No module named 'pkg_resources'

    I'll have to dig into that issue separately.

  4. pawamoy commented on Jul 17, 2023

    @pawamoy
    ContributorAuthor

    https://docs.python.org/3.12/whatsnew/3.12.html#removed:

    easy_install, pkg_resources, setuptools and distutils are no longer provided by default in environments created with venv or bootstrapped with ensurepip, since they are part of the setuptools package. For projects relying on these at runtime, the setuptools project should be declared as a dependency and installed separately (typically, using pip).

    It seems packaging should be added as a test dependency.
    As a fallback maybe we can use importlib.resources instead of pkg_resource.

  5. facelessuser commented on Jul 17, 2023

    @facelessuser
    Collaborator

    I've created the separate issue here: #1357 for the packaging issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions