Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pyright on components directory #4948

Merged
merged 6 commits into from Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -16,7 +16,7 @@ No changes to highlight.

## Other Changes:

No changes to highlight.
- Apply pyright to the `components` directory by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 4948](https://github.com/gradio-app/gradio/pull/4948)

# Version 3.37

Expand Down
3 changes: 1 addition & 2 deletions gradio/components/bar_plot.py
Expand Up @@ -270,7 +270,6 @@ def create_plot(
"bottom-right",
"none",
]
| None
| None = None,
height: int | None = None,
width: int | None = None,
Expand Down Expand Up @@ -366,7 +365,7 @@ def postprocess(self, y: pd.DataFrame | dict | None) -> dict[str, str] | None:
x_title=self.x_title,
y_title=self.y_title,
color_legend_title=self.color_legend_title,
color_legend_position=self.color_legend_position,
color_legend_position=self.color_legend_position, # type: ignore
group_title=self.group_title,
y_lim=self.y_lim,
interactive=self.interactive_chart,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/base.py
Expand Up @@ -371,7 +371,7 @@ def as_example(self, input_data):


class FormComponent:
def get_expected_parent(self) -> type[Form]:
def get_expected_parent(self) -> type[Form] | None:
if getattr(self, "container", None) is False:
return None
return Form
Expand Down
6 changes: 3 additions & 3 deletions gradio/components/line_plot.py
Expand Up @@ -415,10 +415,10 @@ def postprocess(self, y: pd.DataFrame | dict | None) -> dict[str, str] | None:
tooltip=self.tooltip,
x_title=self.x_title,
y_title=self.y_title,
color_legend_title=self.color_legend_title,
color_legend_position=self.color_legend_position,
color_legend_title=self.color_legend_title, # type: ignore
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why pyright is inferring these as str instead of Literal could be a bug

color_legend_position=self.color_legend_position, # type: ignore
stroke_dash_legend_title=self.stroke_dash_legend_title,
stroke_dash_legend_position=self.stroke_dash_legend_position,
stroke_dash_legend_position=self.stroke_dash_legend_position, # type: ignore
x_lim=self.x_lim,
y_lim=self.y_lim,
stroke_dash=self.stroke_dash,
Expand Down
6 changes: 3 additions & 3 deletions gradio/components/scatter_plot.py
Expand Up @@ -459,9 +459,9 @@ def postprocess(self, y: pd.DataFrame | dict | None) -> dict[str, str] | None:
color_legend_title=self.color_legend_title,
size_legend_title=self.size_legend_title,
shape_legend_title=self.size_legend_title,
color_legend_position=self.color_legend_position,
size_legend_position=self.size_legend_position,
shape_legend_position=self.shape_legend_position,
color_legend_position=self.color_legend_position, # type: ignore
size_legend_position=self.size_legend_position, # type: ignore
shape_legend_position=self.shape_legend_position, # type: ignore
interactive=self.interactive_chart,
height=self.height,
width=self.width,
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/video.py
Expand Up @@ -359,7 +359,7 @@ def _format_video(self, video: str | Path | None) -> FileData | None:
"orig_name": Path(video).name,
}

def _format_subtitle(self, subtitle: str | None) -> FileData | None:
def _format_subtitle(self, subtitle: str | Path | None) -> FileData | None:
"""
Convert subtitle format to VTT and process the video to ensure it meets the HTML5 requirements.
Parameters:
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Expand Up @@ -76,6 +76,10 @@ include = [
"/requirements.txt",
]

[tool.pyright]
include = ["gradio/**/*.py"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should catch all python files in the package

exclude = ["gradio/themes/"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will be pretty hard to type themes given the dynamic nature of all the theme props.


[tool.ruff]
target-version = "py37"
extend-select = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/type_check_backend.sh
Expand Up @@ -3,4 +3,4 @@ source scripts/helpers.sh

pip_required

python -m pyright gradio/*.py
python -m pyright