Skip to content

count bare annotations as typed in pyrefly report #3172#3173

Open
jorenham wants to merge 2 commits intofacebook:mainfrom
jorenham:gh-3172
Open

count bare annotations as typed in pyrefly report #3172#3173
jorenham wants to merge 2 commits intofacebook:mainfrom
jorenham:gh-3172

Conversation

@jorenham
Copy link
Copy Markdown
Contributor

@jorenham jorenham commented Apr 17, 2026

Summary

This changes typestats report so that it will treat e.g. bare Final attrs and _: list as typed instead of any, in line with typestats.

Fixes #3172

Test Plan

Added unit tests and integration tests

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Contributor

@connernilsen connernilsen left a comment

Choose a reason for hiding this comment

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

I think this is good. I'll bring it in and see if there are comments internally

@connernilsen
Copy link
Copy Markdown
Contributor

Actually could you rebase first @jorenham? Then I'll pull it in. Just re-request a review from me

Copy link
Copy Markdown
Contributor

@connernilsen connernilsen left a comment

Choose a reason for hiding this comment

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

marking as changes requested for rebase

Copy link
Copy Markdown
Contributor

@connernilsen connernilsen left a comment

Choose a reason for hiding this comment

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

rebase + two other things I found on an extra pass

Comment thread pyrefly/lib/commands/report.rs Outdated
.and_then(|awt| awt.annotation.ty.as_ref().map(Self::is_type_known))
});
let slots =
Self::classify_slot(resolved_ty.or(annotation_text.is_some().then_some(true)));
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.

Should we check the annotation text here to be sure it's a Final? Would this classify something else like value: Callable as typed, even when its parameters are empty?

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.

I think it's ok for a _: Callable to count as typed, as it's equivalent to _: Callable[..., Any]. Because the idea behind n_any only counting things that resolve to _: Any (in typestats at least) is that this is equivalent to _, i.e. no type annotation at all.

Comment thread pyrefly/lib/commands/report.rs Outdated
@jorenham jorenham changed the title count bare Final as typed in pyrefly report #3172 count bare annotations as typed in pyrefly report #3172 Apr 21, 2026
@github-actions github-actions Bot added size/m and removed size/m labels Apr 21, 2026
@jorenham jorenham requested a review from connernilsen April 21, 2026 12:26
@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. ✅

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.

pyrefly report counts pi: Final = 3.14 as any

2 participants