fix: don't comment out return types in stub generation#1724
Merged
DetachHead merged 3 commits intoDetachHead:mainfrom Feb 10, 2026
Merged
fix: don't comment out return types in stub generation#1724DetachHead merged 3 commits intoDetachHead:mainfrom
DetachHead merged 3 commits intoDetachHead:mainfrom
Conversation
Removes the logic that adds inferred return types as comments when generating type stubs. This was creating less complete stubs by commenting out potentially useful type information instead of including it properly. Fixes DetachHead#1694
DetachHead
reviewed
Feb 8, 2026
Comment on lines
-293
to
-304
| // If there was not return type annotation, see if we can infer | ||
| // a type that is not unknown and add it as a comment. | ||
| if (!returnAnnotation) { | ||
| const functionType = this._evaluator.getTypeOfFunction(node); | ||
| if (functionType && isFunction(functionType.functionType)) { | ||
| let returnType = this._evaluator.getInferredReturnType(functionType.functionType); | ||
| returnType = removeUnknownFromUnion(returnType); | ||
| if (!isNever(returnType) && !isUnknown(returnType)) { | ||
| line += ` # -> ${this._evaluator.printType(returnType, { enforcePythonSyntax: true })}:`; | ||
| } | ||
| } | ||
| } |
Owner
There was a problem hiding this comment.
we should keep this, just remove the part that makes it a comment
Contributor
Author
There was a problem hiding this comment.
Done! I've restored the inferred return type logic but changed it to set returnAnnotation instead of appending a comment. Now when there's no explicit return type annotation, the inferred type gets emitted as a proper -> type annotation in the stub rather than as a # -> type: comment.
This comment has been minimized.
This comment has been minimized.
…f comment Restore the inferred return type block but set returnAnnotation instead of appending a comment. This way stubs get proper `-> type` annotations for functions without explicit return types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DetachHead
approved these changes
Feb 9, 2026
Owner
DetachHead
left a comment
There was a problem hiding this comment.
looks good, you just gotta update the tests now
This comment has been minimized.
This comment has been minimized.
…tions The missingTypeStub fourslash tests expected inferred return types to be emitted as comments (e.g. `# -> None:`), but the typeStubWriter change now correctly emits them as proper annotations (`-> None:`). Update all 4 failing test expectations to match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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
Removes the logic that was adding inferred return types as comments when generating type stubs. This was unnecessarily creating less complete stubs by commenting out potentially useful type information.
Changes
typeStubWriter.ts(lines 293-304) that would:# -> int:This logic was deliberately creating incomplete stubs for no clear reason.
Related Issues
Fixes #1694
Test Plan