Skip to content

Add pyrefly type checking - #3859

Draft
MarcoGorelli wants to merge 1 commit into
pallets:mainfrom
MarcoGorelli:pf
Draft

Add pyrefly type checking#3859
MarcoGorelli wants to merge 1 commit into
pallets:mainfrom
MarcoGorelli:pf

Conversation

@MarcoGorelli

Copy link
Copy Markdown

I got curious about taking #3412 forwards, and this is the result. It's a fairly minimal diff, so I've opened a PR

Comment thread src/click/termui.py
def secho(
message: t.Any | None = None,
file: t.IO[t.AnyStr] | None = None,
file: t.IO[t.Any] | None = None,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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

Comment thread src/click/testing.py
if sys.version_info >= (3, 13):
from typing import TypeIs
else:
from typing_extensions import TypeIs

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this typing_extensions import only happens within a if TYPE_CHECKING block, so no runtime dependency is introduced

Comment thread src/click/testing.py
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

using TypeIs instead of just hasattr (which doesn't give type-checkers any info) we avoid the need for casts

Comment thread src/click/types.py
Comment on lines +733 to 734
# pyrefly: ignore [invalid-inheritance] # https://github.com/facebook/pyrefly/issues/4842
class IntRange(_NumberRangeBase[int, int], IntParamType):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

it's under discussion whether pyrefly should flag this (it probably should) facebook/pyrefly#4842

for now I've just suppressed it

@MarcoGorelli
MarcoGorelli marked this pull request as ready for review September 8, 2026 14:27
@davidism
davidism marked this pull request as draft September 8, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant