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

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

Closed
pawamoy opened this issue Jul 17, 2023 · 4 comments · Fixed by #1356
Assignees

Comments

@pawamoy
Copy link
Contributor

pawamoy commented Jul 17, 2023

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.

@facelessuser
Copy link
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.

@facelessuser facelessuser self-assigned this Jul 17, 2023
@facelessuser
Copy link
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.

@pawamoy
Copy link
Contributor Author

pawamoy commented Jul 17, 2023

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.

@facelessuser
Copy link
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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants