Skip to content

Count _ = set[int]() as typed in pyrefly coverage - #5383

Closed
jorenham wants to merge 1 commit into
pyrefly-org:mainfrom
jorenham:coverage/generic-rhs
Closed

jorenham wants to merge 1 commit into
pyrefly-org:mainfrom
jorenham:coverage/generic-rhs

Conversation

@jorenham

Copy link
Copy Markdown
Collaborator

Summary

Before, x = set[int]() would be treated as untyped, because x had no annotations. This is a bit silly though, since set[int] is already explicitly provided by the user, albeit on the RHS. This makes it so that pyrefly coverage {report,coverage} will consider x to be typed.

In case of unknown rhs, e.g. from schrodinger import cat; cats = cat[None](), cats will still be considered untyped. Because cat could be a generic type, but it could also be dict[None, () -> SomethingElse] -- there's no way to tell 🤷.

I ran into this in the wild in Hypothesis recently:

Test Plan

Tests added

@jorenham jorenham added the coverage Issues related to `pyrefly coverage` label Oct 26, 2026
@meta-cla meta-cla Bot added the cla signed label Oct 26, 2026
@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D127555133. (Because this pull request was imported automatically, there will not be any future comments.)

@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. ✅

@stroxler stroxler 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 413a7ef Oct 27, 2026
@meta-codesync meta-codesync Bot added the Merged label Oct 27, 2026
@meta-codesync

meta-codesync Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 413a7ef.

@jorenham
jorenham deleted the coverage/generic-rhs branch October 27, 2026 15:40
meta-codesync Bot pushed a commit that referenced this pull request Nov 5, 2026
Summary:
Before, `x = set[int]()` would be treated as untyped, because `x` had no annotations. This is a bit silly though, since `set[int]` is already explicitly provided by the user, albeit on the RHS. This makes it so that `pyrefly coverage {report,coverage}` will consider `x`  to be typed.

In case of unknown rhs, e.g. `from schrodinger import cat; cats = cat[None]()`, `cats` will still be considered untyped. Because `cat` could be a generic type, but it could also be `dict[None, () -> SomethingElse]` -- there's no way to tell 🤷.

I ran into this in the wild in [Hypothesis](https://github.com/HypothesisWorks/hypothesis/) recently:

-  [`default_variable = DynamicVariable[Optional["settings"]](None)`](https://github.com/HypothesisWorks/hypothesis/blob/a2406edcd532e02400c8e20e6a131b791d3c11b6/hypothesis/src/hypothesis/_settings.py#L416)
- [`reporter = DynamicVariable[ReporterT](default)`](https://github.com/HypothesisWorks/hypothesis/blob/a2406edcd532e02400c8e20e6a131b791d3c11b6/hypothesis/src/hypothesis/reporting.py#L28)

- [x] I am a human <sub>(no way to know for sure, but I certainly hope so!)</sub>, and I fully understand the code I am submitting.

X-link: #5383

Reviewed By: stroxler

Differential Revision: D127555133

fbshipit-source-id: 726d371acad581fdc939d1947f82fb0ac904a124
meta-codesync Bot pushed a commit that referenced this pull request Nov 11, 2026
…efly coverage` (#5613)

Summary:
Following #5383 and #5552, this relaxes the typable classifier some more for module-level, so that non-generic class constructors now also are counted as implicitly typed, e.g. `BASE_DIR = Path(".")`.

- [x] I am a human, and I fully understand the code I am submitting.

Pull Request resolved: #5613

Test Plan: there are tests

Reviewed By: stroxler

Differential Revision: D131224148

fbshipit-source-id: e7fceed6e1aca06f8805bb39cda81288bffa8f5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed coverage Issues related to `pyrefly coverage` Merged quansight size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants