Skip to content

Suppress unannotated-return for @no_type_check functions#3904

Closed
nitishagar wants to merge 1 commit into
facebook:mainfrom
nitishagar:nitishagar/issue-3561-no-type-check-unannotated-return
Closed

Suppress unannotated-return for @no_type_check functions#3904
nitishagar wants to merge 1 commit into
facebook:mainfrom
nitishagar:nitishagar/issue-3561-no-type-check-unannotated-return

Conversation

@nitishagar

Copy link
Copy Markdown
Contributor

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 #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

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
@github-actions

Copy link
Copy Markdown

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

@yangdanny97

Copy link
Copy Markdown
Contributor

@NathanTempest this looks ok to merge

@NathanTempest

Copy link
Copy Markdown
Contributor

Thanks @nitishagar for the nicely targeted fix. The test coverage is solid too, LGTM and importing.

@meta-codesync

meta-codesync Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D109462421.

@rchen152 rchen152 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in e4d4bf1 Jun 23, 2026
@meta-codesync meta-codesync Bot added the Merged label Jun 23, 2026
@meta-codesync

meta-codesync Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@NathanTempest merged this pull request in e4d4bf1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

false positive unannotated-return for @no_type_check function

4 participants