Narrow StringOutput.OutputType to non-optional#338
Open
broken-circle wants to merge 1 commit into
Open
Conversation
`StringOutput.output(from:)` never returns an optional string, so the associated `OutputType` does not need to be optional. Narrow its type to `String`.
Member
Author
|
@iCharlesHu, somewhat related question: the 1.0 beta release includes the deprecated |
Contributor
|
Personally I think |
Member
Author
|
Exactly what I was thinking! |
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.
StringOutput.output(from:)never returns an optional string, so the associatedOutputTypedoes not need to be optional. This PR narrows its type toString. This is a breaking API change, but one I think is worth landing before 1.0.The current behavior is that the user always gets a non-optional
String. Invalid byte sequences are replaced with the Unicode replacement character (U+FFFD), which is the behavior ofString(decoding:as:)thatoutput(from:)already uses viaString(decodingBytes:as:). This also makesStringOutputconsistent withDataOutput, whoseOutputTypeis non-optionalData.The optional type was introduced in iCharlesHu/Subprocess/main@
7f9cea8and brought over to this repository in the initial commit. I couldn't find a reason the type was optional. The type permitsnil, but no code path produces it; if returningnilon invalid input is behavior we want, let me know and I'll look into it as a follow-up PR.String(validating:as:)would be the appropriate API, but it's gated on macOS 15+ (Subprocess supports macOS 13+), so the implementation will require availability-gated fallbacks.