Repository navigation
Fix Python DetachStream return nullability - #231
Merged
Merged
Conversation
Record exact nullable results for DataReader/DataWriter and their declaring interfaces. Cover generated stubs, guarded and unguarded strict consumers, and native stream detach states. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ❌ Failed
|
shisan (qiutongMS)
approved these changes
Oct 30, 2026
Preserve both Python CI checks and adapt the DetachStream regression to main's generated src layout and import helpers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
shisan (qiutongMS)
approved these changes
Oct 30, 2026
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.
Summary
Correct generated Python
DataWriter.detach_stream()andDataReader.detach_stream()return types toIOutputStream | NoneandIInputStream | None. An unbound writer, a buffer-backed reader, or a repeated detach can returnNone, but the generated stubs previously declared a non-null stream.The fix adds exact reviewed facts for these classes and their
IDataWriter/IDataReaderdeclarations to the existing null-result table. Regression coverage checks class protocols, package and namespace facades, and independently resolved interface projections without widening unrelated results.Reproduction
Prerequisites: Windows with the Windows SDK installed, the matching
dynwinrtPython runtime, and mypy.Steps:
repro.py, then runpython -m mypy --strict repro.pyandpython repro.py:Actual behavior: Strict checking accepts the unchecked access, but execution raises
AttributeError: 'NoneType' object has no attribute 'flush_async'.After the fix: Strict checking rejects the access because the result can be
None. Saving the result and checkingstream is not Nonebefore using it is accepted. Runtime behavior is unchanged.Validation
Strict mypy and Pyright consumers accept guarded access and reject unchecked access through classes, protocols and declaring interfaces. Native calls verify absent streams, the original stream identity on the first attached detach, and
Noneon repeated detach for both readers and writers. The generatedsrc-layout package was also installed and exercised through itssite-packagesimport rather than the source directory.Compatibility and risks
Regenerate and reinstall existing bindings to receive the corrected declarations. Previously accepted unchecked calls may now require a
Noneguard. Native null conversion and the broader inline Python annotations are unchanged.