Add pyrefly type checking - #3859
MarcoGorelli wants to merge 1 commit into
Conversation
| def secho( | ||
| message: t.Any | None = None, | ||
| file: t.IO[t.AnyStr] | None = None, | ||
| file: t.IO[t.Any] | None = None, |
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 |
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
| if hasattr(input, "read"): | ||
| rv = _find_binary_reader(t.cast("t.IO[t.Any]", input)) | ||
| if _has_read(input): | ||
| rv = _find_binary_reader(input) |
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
| # pyrefly: ignore [invalid-inheritance] # https://github.com/facebook/pyrefly/issues/4842 | ||
| class IntRange(_NumberRangeBase[int, int], IntParamType): |
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 Thanks for taking the time to add this, but I am not sure that we can accept it. All the pallets projects try to run the same type checker on the implementation which is mypy, until @davidism decides for us to make a switch. But we are interested is adding other type checkers to check the types we export as the type checkers become mature. That is also another call by @davidism. |
I got curious about taking #3412 forwards, and this is the result. It's a fairly minimal diff, so I've opened a PR