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

fix: Test xml.etree.ElementTree.Element truth value by 'is not None' #2459

Merged
merged 1 commit into from
Mar 20, 2024

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Mar 20, 2024

Description

Resolves #2453

In Python 3.14 testing the truth value of an xml.etree.ElementTree.Element is deprecated and will raise an exception. As of Python 3.12 this behavior will raise a DeprecationWarning:

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.

To avoid this, determine the truth element by using the elem is not None method.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* In Python 3.14 testing the truth value of an xml.etree.ElementTree.Element is
  deprecated and will raise an exception. As of Python 3.12 this behavior will
  raise a DeprecationWarning:

  ```
  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.
  ```

  To avoid this, determine the truth element by using the 'elem is not None'
  method.
   - c.f. https://docs.python.org/3.12/library/xml.etree.elementtree.html#element-objects

* In Python 3.14 testing the truth value of an xml.etree.ElementTree.Element is
  deprecated and will raise an exception. As of Python 3.12 this behavior will
  raise a DeprecationWarning:

  ```
  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.
  ```

  To avoid this, determine the truth element by using the 'elem is not None'
  method.
@matthewfeickert matthewfeickert added fix A bug fix need-to-backport tmp label until can be backported to patch release branch labels Mar 20, 2024
@matthewfeickert matthewfeickert self-assigned this Mar 20, 2024
@matthewfeickert
Copy link
Member Author

This won't get properly fully tested until Python 3.12 is added to the CI matrix.

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 98.21%. Comparing base (50f1076) to head (7df47f2).

Files Patch % Lines
src/pyhf/writexml.py 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2459      +/-   ##
==========================================
- Coverage   98.23%   98.21%   -0.03%     
==========================================
  Files          69       69              
  Lines        4541     4541              
  Branches      804      804              
==========================================
- Hits         4461     4460       -1     
- Misses         46       48       +2     
+ Partials       34       33       -1     
Flag Coverage Δ
contrib 97.79% <0.00%> (-0.03%) ⬇️
doctest 98.08% <0.00%> (-0.03%) ⬇️
unittests-3.10 96.23% <0.00%> (-0.03%) ⬇️
unittests-3.11 96.23% <0.00%> (-0.03%) ⬇️
unittests-3.8 96.25% <0.00%> (-0.03%) ⬇️
unittests-3.9 96.27% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matthewfeickert
Copy link
Member Author

I'm going to approve and merge this myself. As always, PRs approved by a single core dev can be reverted as needed by the rest of the dev team.

@matthewfeickert matthewfeickert merged commit a0d94b9 into main Mar 20, 2024
21 of 22 checks passed
@matthewfeickert matthewfeickert deleted the fix/guard-regex-for-py-3-14 branch March 20, 2024 08:58
@matthewfeickert matthewfeickert added the tests pytest label Mar 20, 2024
@matthewfeickert matthewfeickert removed the need-to-backport tmp label until can be backported to patch release branch label May 30, 2024
@matthewfeickert
Copy link
Member Author

@meeseeksdev backport to release/v0.7.x

meeseeksmachine pushed a commit to meeseeksmachine/pyhf that referenced this pull request May 30, 2024
matthewfeickert added a commit that referenced this pull request May 30, 2024
…not None' (#2499)

* Backport PR #2459
* In Python 3.14 testing the truth value of an xml.etree.ElementTree.Element is
  deprecated and will raise an exception. As of Python 3.12 this behavior will
  raise a DeprecationWarning:

  ```
  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.
  ```

  To avoid this, determine the truth element by using the 'elem is not None'
  method.
   - c.f. https://docs.python.org/3.12/library/xml.etree.elementtree.html#element-objects

Co-authored-by: Matthew Feickert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix tests pytest
Projects
Status: Done
1 participant