Skip to content

fix: don't comment out return types in stub generation#1724

Merged
DetachHead merged 3 commits intoDetachHead:mainfrom
veeceey:fix/issue-1694-dont-comment-return-types
Feb 10, 2026
Merged

fix: don't comment out return types in stub generation#1724
DetachHead merged 3 commits intoDetachHead:mainfrom
veeceey:fix/issue-1694-dont-comment-return-types

Conversation

@veeceey
Copy link
Copy Markdown
Contributor

@veeceey veeceey commented Feb 8, 2026

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

  • Removed the code block in typeStubWriter.ts (lines 293-304) that would:
    1. Check if a function has no return type annotation
    2. Infer the return type
    3. Add it as a comment like # -> int:

This logic was deliberately creating incomplete stubs for no clear reason.

Related Issues

Fixes #1694

Test Plan

  • TypeScript compilation passes without errors
  • No existing tests were found for the stub writer functionality
  • Manual verification would require:
    1. Running stub generation on code with unannotated functions
    2. Verifying the generated stubs no longer have commented return types

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
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 })}:`;
}
}
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

we should keep this, just remove the part that makes it a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@github-actions

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>
Copy link
Copy Markdown
Owner

@DetachHead DetachHead left a comment

Choose a reason for hiding this comment

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

looks good, you just gotta update the tests now

@github-actions

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>
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@DetachHead DetachHead enabled auto-merge (squash) February 10, 2026 02:28
@DetachHead DetachHead disabled auto-merge February 10, 2026 02:28
@DetachHead DetachHead merged commit eeca15f into DetachHead:main Feb 10, 2026
14 checks passed
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.

don't comment out return types when generating stubs

2 participants