Skip to content

Adjust deprecation warning re: testing truth value of xml.etree.ElementTree.Element #119577

Closed

Activity

  1. added 2 commits that reference this issue on May 26, 2024
  2. serhiy-storchaka commented on May 27, 2024

    @serhiy-storchaka
    Member

    AFAIK, the plan was to return True instead of raising an exception.

  3. jacobtylerwalls commented on May 28, 2024

    @jacobtylerwalls
    ContributorAuthor

    In favor of raising an error: #83122 (comment)
    In favor of DeprecationWarning being the choice for an exception vs. FutureWarning being the choice to for a behavior change: #83122 (comment)

    cc/ @gpshead who reviewed #31149, which changed FutureWarning to DeprecationWarning and documented that an exception would be raised.

  4. serhiy-storchaka commented on May 28, 2024

    @serhiy-storchaka
    Member

    Raising an exception in __bool__() is extremely uncommon behavior. For now, there is only one special case -- NotImplemented, and it is a very special case. On other hand, there is a precedence of datetime.time -- the midnight had the false boolean value, and now it has lost its special meaning and has the same boolean value like all other datetime.time values.

  5. gpshead commented on May 28, 2024

    @gpshead
    Member

    We did document that it would raise an exception in the future. But I agree that that is unusual.

    Lets be conservative and delay the __bool__ behavior change on Element for a few more releases until the 3.16 timeframe to let the DeprecationWarning be more widely seen and acted upon in existing code. In 3.16+ we can (edit updated:) make its __bool__ method return true. Thus making all instances truthy as most class instances are.

    What that means is that we need a PR to update the docs and the DeprecationWarning error message to reflect the new plan.

    bool raising an exception does have valid uses: Such as when a class that is commonly mistaken for an actual boolean value in some API designs is easily misused in the wrong context. Element doesn't seem like one of those.

  6. serhiy-storchaka commented on May 28, 2024

    @serhiy-storchaka
    Member

    We cannot just remove __bool__. Element has __len__, and this is the reason why childless elements had the false boolean value, why this deprecation started. It should be a method that always returns True. Yes, inconsistency between __len__ and __bool__ is also unusual, but this considered lesser evil than having the false boolean value for otherwise normal elements.

  7. changed the title [-]Make testing truth value of `xml.etree.ElementTree.Element` raise an exception[/-] [+]Adjust deprecation warning re: testing truth value of `xml.etree.ElementTree.Element`[/+] on May 30, 2024
  8. added 2 commits that reference this issue on May 30, 2024
  9. jacobtylerwalls commented on Jun 6, 2024

    @jacobtylerwalls
    ContributorAuthor

    What that means is that we need a PR to update the docs and the DeprecationWarning error message to reflect the new plan.

    New PR: #119762

  10. added a commit that references this issue on Jun 7, 2024
  11. added a commit that references this issue on Jun 7, 2024
  12. added 2 commits that reference this issue on Jun 7, 2024
  13. added a commit that references this issue on Jun 7, 2024
  14. added a commit that references this issue on Jul 11, 2024
  15. added a commit that references this issue on Jul 17, 2024
  16. added a commit that references this issue on Aug 6, 2024
  17. hugovk commented on Aug 8, 2024

    @hugovk
    Member

    Triage: closing because the PR has been merged, please re-open if still needed. Thanks!

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

Metadata

Metadata

Labels

3.14bugs and security fixestopic-XMLtype-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions