-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add pyrefly type checking #3859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,11 @@ | |
|
|
||
| from .core import Command | ||
|
|
||
| if sys.version_info >= (3, 13): | ||
| from typing import TypeIs | ||
| else: | ||
| from typing_extensions import TypeIs | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
|
|
||
| if sys.platform == "win32": | ||
| CaptureMode: t.TypeAlias = t.Literal["sys"] # pyright: ignore[reportRedeclaration] | ||
| else: | ||
|
|
@@ -208,12 +213,16 @@ def mode(self) -> str: | |
| return self._mode | ||
|
|
||
|
|
||
| def _has_read(x: object) -> TypeIs[t.IO[t.Any]]: | ||
| return hasattr(x, "read") | ||
|
|
||
|
|
||
| def make_input_stream( | ||
| input: str | bytes | t.IO[t.Any] | None, charset: str | ||
| ) -> t.BinaryIO: | ||
| # Is already an input stream. | ||
| if hasattr(input, "read"): | ||
| rv = _find_binary_reader(t.cast("t.IO[t.Any]", input)) | ||
| if _has_read(input): | ||
| rv = _find_binary_reader(input) | ||
|
Comment on lines
-215
to
+225
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using |
||
|
|
||
| if rv is not None: | ||
| return rv | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -730,6 +730,7 @@ def __repr__(self) -> str: | |
| return "INT" | ||
|
|
||
|
|
||
| # pyrefly: ignore [invalid-inheritance] # https://github.com/facebook/pyrefly/issues/4842 | ||
| class IntRange(_NumberRangeBase[int, int], IntParamType): | ||
|
Comment on lines
+733
to
734
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| """Restrict an :data:`click.INT` value to a range of accepted | ||
| values. See :ref:`ranges`. | ||
|
|
@@ -762,6 +763,7 @@ def __repr__(self) -> str: | |
| return "FLOAT" | ||
|
|
||
|
|
||
| # pyrefly: ignore [invalid-inheritance] # https://github.com/facebook/pyrefly/issues/4842 | ||
| class FloatRange(_NumberRangeBase[float, float], FloatParamType): | ||
| """Restrict a :data:`click.FLOAT` value to a range of accepted | ||
| values. See :ref:`ranges`. | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnyStris a typevar, so it's not meant to be used in only a single place in a functionI've updated
t.IO[t.AnyStr]tot.IO[t.Any]then