Suppress unannotated-return for @no_type_check functions#3904
Closed
nitishagar wants to merge 1 commit into
Closed
Suppress unannotated-return for @no_type_check functions#3904nitishagar wants to merge 1 commit into
nitishagar wants to merge 1 commit into
Conversation
A function decorated with `typing.no_type_check` (or the `typing_extensions` alias) should not produce an `[unannotated-return]` diagnostic, since the decorator explicitly opts the entire function out of type checking. The fix threads recognition of `@no_type_check` through the same decorator-flag pipeline already used by `@abc.abstractmethod`: a new `FunctionKind::NoTypeCheck` variant is recognised in `FunctionKind::from_name`, surfaces as `SpecialDecorator::NoTypeCheck`, and sets `FuncFlags::has_no_type_check = true`. The `[unannotated-return]` emission site is then guarded by `!def.metadata.flags.has_no_type_check`, so the error is suppressed for these functions while all other functions are unaffected. Fixes facebook#3561 Test Plan: - cargo test -p pyrefly --lib untyped_def_behaviors - cargo test -p pyrefly --lib - python3 test.py --no-test --no-conformance --no-jsonschema
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Contributor
|
@NathanTempest this looks ok to merge |
Contributor
|
Thanks @nitishagar for the nicely targeted fix. The test coverage is solid too, LGTM and importing. |
NathanTempest
approved these changes
Jun 23, 2026
Contributor
|
@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D109462421. |
rchen152
approved these changes
Jun 23, 2026
rchen152
left a comment
Contributor
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Contributor
|
@NathanTempest merged this pull request in e4d4bf1. |
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.
A function decorated with
typing.no_type_check(or thetyping_extensionsalias) should not produce an
[unannotated-return]diagnostic, since thedecorator explicitly opts the entire function out of type checking.
The fix threads recognition of
@no_type_checkthrough the same decorator-flagpipeline already used by
@abc.abstractmethod: a newFunctionKind::NoTypeCheckvariant is recognised in
FunctionKind::from_name, surfaces asSpecialDecorator::NoTypeCheck, and setsFuncFlags::has_no_type_check = true.The
[unannotated-return]emission site is then guarded by!def.metadata.flags.has_no_type_check, so the error is suppressed for thesefunctions while all other functions are unaffected.
Fixes #3561
Test Plan: