Repository navigation
Conversation
Port the `typer/testing.py` part of pallets/click#3139, released in Click 8.3.2. `_NamedTextIOWrapper` gets an empty `close()`, so dropping the wrapper no longer closes the `StreamMixer` buffer that `invoke()` reads afterwards, and `StreamMixer.__del__` goes, so a stream captured inside the command stays writable after `invoke()` returns.
The empty close method is to prevent the buffer from being closed by someone who doesn't own it. The del method was added to fix some race condition discovered with freethreaded Python 3.14. My diagnosis was that adding the del method made test case work, but the ownership issue was the root cause for both of them. I would suggest to get both fixes merged, but it's up to the maintainers with how they want the pull requests organized. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ports the
typer/testing.pyhalf of the Click fix pallets/click#3139, which shipped in Click 8.3.2. Refs #1289, a discussion, so nothing closes on merge._NamedTextIOWrapperwraps aStreamMixerbuffer. ATextIOWrappercloses its buffer onclose()and on garbage collection. pytest's live logging swapssys.stdoutmid-command, the wrapper dies, andinvoke()then fails atoutstreams[0].getvalue(). The fix has Click's two hunks. The wrapper gets an emptyclose(), andStreamMixer.__del__goes, because it closed the buffers again afterinvoke()returned.Each new test in
tests/test_termui.pypins one hunk:I did not add a release-notes entry, since
latest-changeswrites it on merge.@svlandeg, this is the minimal PR you asked for in #1289. I kept the
__del__removal because the second test fails without it. If you would prefer only theclose()hunk here, I'll drop it. I have two more small Click ports built and will hold them until this one is reviewed, unless you'd rather not get them at all.