Skip to content

Special-case logging.Logger and re.Pattern in pyrefly coverage - #5552

Closed
jorenham wants to merge 1 commit into
pyrefly-org:mainfrom
jorenham:coverage/special-case-logging-re
Closed

jorenham wants to merge 1 commit into
pyrefly-org:mainfrom
jorenham:coverage/special-case-logging-re

Conversation

@jorenham

@jorenham jorenham commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

I noticed in several projects now that they tend to leave a module-level logger = logging.getLogger() unannotated in modules without __all__, and don't consider it to be public API. But pyrefly coverage check, due to logger not having a leading underscore, will consider it as untyped typable regardless. This is a common enough pattern that I think it's worth special-casing logging.getLogger to count it as implicitly typed when unannotated.

To confirm my assumptions,I had an agent do a quick code survey (on my local uv cache), and it found 4,204 logging.getLogger calls of which only 108 were annotated and public.
For re.compile it's very similar, with 137 annotated public module-level re.compile names out of 3,902 total re.compile calls, so I think that one is also worth special-casing.
I had the agent look for other similar module-level constructor calls, but these two were by far the most common.

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Integration tests added

@jorenham jorenham added the coverage Issues related to `pyrefly coverage` label Nov 5, 2026
@meta-cla meta-cla Bot added the cla signed label Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Optional recommendations:

  • If this PR addresses an open issue, please link the issue in the PR description and claim it.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

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

@meta-codesync

meta-codesync Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

@rchen152 rchen152 assigned rchen152 and unassigned maggiemoss Nov 7, 2026
@rchen152
rchen152 requested review from rchen152 and removed request for maggiemoss November 7, 2026 00:49

@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 3a261cc Nov 7, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 7, 2026
@meta-codesync

meta-codesync Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@rchen152 merged this pull request in 3a261cc.

@jorenham
jorenham deleted the coverage/special-case-logging-re branch November 7, 2026 09:19
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants