Skip to content

Conversation

CoolCat467
Copy link
Member

In this pull request, we implement trio.Event.__bool__() to reduce bugs.

Closes #3238

Copy link

codecov bot commented Aug 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00000%. Comparing base (77dd921) to head (02c3794).

Additional details and impacted files
@@               Coverage Diff               @@
##                 main        #3322   +/-   ##
===============================================
  Coverage   100.00000%   100.00000%           
===============================================
  Files             125          125           
  Lines           19251        19263   +12     
  Branches         1304         1304           
===============================================
+ Hits            19251        19263   +12     
Files with missing lines Coverage Δ
src/trio/_sync.py 100.00000% <100.00000%> (ø)
src/trio/_tests/test_sync.py 100.00000% <100.00000%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CoolCat467 CoolCat467 requested a review from A5rocks August 25, 2025 03:11
@Zac-HD
Copy link
Member

Zac-HD commented Aug 25, 2025

This is a strange request, but could we raise an error if some global variable is set? That way I could monkeypatch in the error behavior, even before we deal with every other trio deprecation.

@A5rocks
Copy link
Contributor

A5rocks commented Aug 25, 2025

I think you can set a specific filterwarning configuration s.t. a specific warning will raise instead of warning.

(in this case, I think just setting the PYTHONWARNINGS envvar to error:<the message>:DeprecationWarning should work?)

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -23,6 +23,12 @@ async def test_Event() -> None:
assert not e.is_set()
assert e.statistics().tasks_waiting == 0

with pytest.warns(
DeprecationWarning,
match=r"trio\.Event\.__bool__ is deprecated since Trio 0\.30\.1; use trio\.Event\.is_set instead \(https://github.com/python-trio/trio/issues/3238\)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably going to be 0.31.0 but I can update this whenever I make a release...

@A5rocks
Copy link
Contributor

A5rocks commented Aug 25, 2025

The unfortunate thing is this actually breaks --enable-error-code=truthy-bool because that only warns about inheriting __bool__ from object. But, I doubt anyone actually relies on that behavior! (in turn, it should now get flagged by --enable-error-code=redundant-expr... but doesn't? I think that's a bug)

@TeamSpen210
Copy link
Contributor

Define it only if not TYPE_CHECKING, then mypy should continue to warn. Or typing_extensions.deprecated. Hmm might want to start using the latter in general...

@A5rocks
Copy link
Contributor

A5rocks commented Aug 25, 2025

Well, supposedly if not TYPE_CHECKING annoys jedi. But yeah one of those might be nice if it works.

@CoolCat467 CoolCat467 force-pushed the event-bool-exception branch from b1b5314 to 02c3794 Compare August 26, 2025 01:35
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 this pull request may close these issues.

Define trio.Event.__bool__() to reduce bugs
4 participants