scikit-hep / pyhf

pure-Python HistFactory implementation with tensors and autodiff
https://pyhf.readthedocs.io/
Apache License 2.0
283 stars 83 forks source link

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

Closed matthewfeickert closed 6 months ago

matthewfeickert commented 6 months ago

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

Before Merging

For the PR Assignees:

* 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
matthewfeickert commented 6 months ago

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

codecov[bot] commented 6 months ago

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 :warning:
Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | Coverage Δ | | |---|---|---| | [contrib](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `97.79% <0.00%> (-0.03%)` | :arrow_down: | | [doctest](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `98.08% <0.00%> (-0.03%)` | :arrow_down: | | [unittests-3.10](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `96.23% <0.00%> (-0.03%)` | :arrow_down: | | [unittests-3.11](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `96.23% <0.00%> (-0.03%)` | :arrow_down: | | [unittests-3.8](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `96.25% <0.00%> (-0.03%)` | :arrow_down: | | [unittests-3.9](https://app.codecov.io/gh/scikit-hep/pyhf/pull/2459/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep) | `96.27% <0.00%> (-0.03%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-hep#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

matthewfeickert commented 6 months ago

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 commented 4 months ago

@meeseeksdev backport to release/v0.7.x