Add pyrefly type checking - #3859
Draft
MarcoGorelli wants to merge 1 commit into
Draft
Conversation
MarcoGorelli
commented
Sep 8, 2026
| def secho( | ||
| message: t.Any | None = None, | ||
| file: t.IO[t.AnyStr] | None = None, | ||
| file: t.IO[t.Any] | None = None, |
Author
There was a problem hiding this comment.
AnyStr is a typevar, so it's not meant to be used in only a single place in a function
I've updated t.IO[t.AnyStr] to t.IO[t.Any] then
| if sys.version_info >= (3, 13): | ||
| from typing import TypeIs | ||
| else: | ||
| from typing_extensions import TypeIs |
Author
There was a problem hiding this comment.
this typing_extensions import only happens within a if TYPE_CHECKING block, so no runtime dependency is introduced
Comment on lines
-215
to
+225
| if hasattr(input, "read"): | ||
| rv = _find_binary_reader(t.cast("t.IO[t.Any]", input)) | ||
| if _has_read(input): | ||
| rv = _find_binary_reader(input) |
Author
There was a problem hiding this comment.
using TypeIs instead of just hasattr (which doesn't give type-checkers any info) we avoid the need for casts
Comment on lines
+733
to
734
| # pyrefly: ignore [invalid-inheritance] # https://github.com/facebook/pyrefly/issues/4842 | ||
| class IntRange(_NumberRangeBase[int, int], IntParamType): |
Author
There was a problem hiding this comment.
it's under discussion whether pyrefly should flag this (it probably should) facebook/pyrefly#4842
for now I've just suppressed it
MarcoGorelli
marked this pull request as ready for review
September 8, 2026 14:27
davidism
marked this pull request as draft
September 8, 2026 14:59
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.
I got curious about taking #3412 forwards, and this is the result. It's a fairly minimal diff, so I've opened a PR