Skip to content

Commit

Permalink
Enable ARG and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jan 18, 2024
1 parent 3c962a5 commit f347fdc
Show file tree
Hide file tree
Showing 16 changed files with 30 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradio/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pyodide.http import pyfetch as pyodide_pyfetch # type: ignore
except ImportError:

async def pyodide_pyfetch(*args, **kwargs):
async def pyodide_pyfetch(*_args, **_kwargs):
raise NotImplementedError(
"pyodide.http.pyfetch is not available in this environment."
)
Expand Down
7 changes: 5 additions & 2 deletions gradio/cli/commands/components/_create_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,17 @@ def delete_contents(directory: str | Path) -> None:


def _create_frontend(
name: str, component: ComponentFiles, directory: Path, package_name: str
name: str, # noqa: ARG001
component: ComponentFiles,
directory: Path,
package_name: str,
):
frontend = directory / "frontend"
frontend.mkdir(exist_ok=True)

p = Path(inspect.getfile(gradio)).parent

def ignore(s, names):
def ignore(_src, names):
ignored = []
for n in names:
if (
Expand Down
5 changes: 1 addition & 4 deletions gradio/cli/commands/components/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"""


def _ignore(s, names):
def _ignore(_src, names):
ignored = []
for n in names:
if "__pycache__" in n or n.startswith("dist") or n.startswith("node_modules"):
Expand Down Expand Up @@ -88,9 +88,6 @@ def _publish(
Path,
Argument(help=f"Path to the wheel directory. Default is {Path('.') / 'dist'}"),
] = Path(".") / "dist",
bump_version: Annotated[
bool, Option(help="Whether to bump the version number.")
] = True,
upload_pypi: Annotated[bool, Option(help="Whether to upload to PyPI.")] = True,
pypi_username: Annotated[str, Option(help="The username for PyPI.")] = "",
pypi_password: Annotated[str, Option(help="The password for PyPI.")] = "",
Expand Down
6 changes: 5 additions & 1 deletion gradio/components/json_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def preprocess(self, payload: dict | list | str | None) -> dict | list | str | N
def example_inputs(self) -> Any:
return {"foo": "bar"}

def flag(self, payload: Any, flag_dir: str | Path = "") -> str:
def flag(
self,
payload: Any,
flag_dir: str | Path = "", # noqa: ARG002
) -> str:
return json.dumps(payload)

def read_from_flag(self, payload: Any):
Expand Down
2 changes: 1 addition & 1 deletion gradio/components/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class State(Component):
def __init__(
self,
value: Any = None,
render: bool = True,
render: bool = True, # noqa: ARG002
):
"""
Parameters:
Expand Down
2 changes: 1 addition & 1 deletion gradio/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def dict(self, **kwargs):
return super().dict(**kwargs)["root"]

@classmethod
def schema(cls, **kwargs):
def schema(cls, **_kwargs):
# XXX: kwargs are ignored.
return schema_of(cls.__fields__["root"].type_) # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion gradio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class EventListenerMethod:


class EventListener(str):
def __new__(cls, event_name, *args, **kwargs):
def __new__(cls, event_name, *_args, **_kwargs):
return super().__new__(cls, event_name)

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion gradio/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def from_model(model_name: str, hf_token: str | None, alias: str | None, **kwarg
sources=["upload"], type="filepath", label="Input", render=False
),
"outputs": components.Label(label="Class", render=False),
"preprocess": lambda i: to_binary,
"preprocess": lambda _: to_binary,
"postprocess": lambda r: postprocess_label(
{i["label"].split(", ")[0]: i["score"] for i in r.json()}
),
Expand Down
4 changes: 2 additions & 2 deletions gradio/flagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def setup(self, components: list[Component], flagging_dir: str | Path):
def flag(
self,
flag_data: list[Any],
flag_option: str = "",
username: str | None = None,
flag_option: str = "", # noqa: ARG002
username: str | None = None, # noqa: ARG002
) -> int:
flagging_dir = self.flagging_dir
log_filepath = Path(flagging_dir) / "log.csv"
Expand Down
2 changes: 1 addition & 1 deletion gradio/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def _add_mocked_oauth_routes(app: fastapi.FastAPI) -> None:

# Define OAuth routes
@app.get("/login/huggingface")
async def oauth_login(request: fastapi.Request):
async def oauth_login(request: fastapi.Request): # noqa: ARG001
"""Fake endpoint that redirects to HF OAuth page."""
return RedirectResponse("/login/callback")

Expand Down
2 changes: 1 addition & 1 deletion gradio/ranged_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def set_range_headers(self, range: ClosedRange) -> None:
self.headers["content-length"] = str(content_length)
pass

async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: # noqa: ARG002
if self.stat_result is None:
try:
stat_result = await aio_stat(self.path)
Expand Down
10 changes: 6 additions & 4 deletions gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def get_token(request: fastapi.Request) -> dict:

@app.get("/app_id")
@app.get("/app_id/")
def app_id(request: fastapi.Request) -> dict:
def app_id(request: fastapi.Request) -> dict: # noqa: ARG001
return {"app_id": app.get_blocks().app_id}

@app.get("/dev/reload", dependencies=[Depends(login_check)])
Expand Down Expand Up @@ -354,8 +354,7 @@ def main(request: fastapi.Request, user: str = Depends(get_current_user)):

@app.get("/info/", dependencies=[Depends(login_check)])
@app.get("/info", dependencies=[Depends(login_check)])
def api_info(serialize: bool = True):
# config = app.get_blocks().get_api_info()
def api_info():
return app.get_blocks().get_api_info() # type: ignore

@app.get("/config/", dependencies=[Depends(login_check)])
Expand Down Expand Up @@ -489,7 +488,10 @@ async def file(path_or_url: str, request: fastapi.Request):
dependencies=[Depends(login_check)],
)
async def stream(
session_hash: str, run: int, component_id: int, request: fastapi.Request
session_hash: str,
run: int,
component_id: int,
request: fastapi.Request, # noqa: ARG001
):
stream: list = (
app.get_blocks()
Expand Down
6 changes: 1 addition & 5 deletions gradio/themes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
go_btn = gr.Button("Go", variant="primary")
clear_btn = gr.Button("Clear", variant="secondary")

def go(*args):
def go(*_args):
time.sleep(3)
return "https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpgjpg"

Expand Down Expand Up @@ -121,10 +121,6 @@ def clear():
chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")
chat_btn = gr.Button("Add messages")

def chat(history):
time.sleep(2)
yield [["How are you?", "I am good."]]

chat_btn.click(
lambda history: history
+ [["How are you?", "I am good."]]
Expand Down
6 changes: 1 addition & 5 deletions gradio/themes/builder_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_doc_theme_var_groups():
go_btn = gr.Button("Go", variant="primary")
clear_btn = gr.Button("Clear", variant="secondary")

def go(*args):
def go(*_args):
time.sleep(3)
return "https://gradio-static-files.s3.us-west-2.amazonaws.com/header-image.jpg"

Expand Down Expand Up @@ -437,10 +437,6 @@ def clear():
chatbot = gr.Chatbot([("Hello", "Hi")], label="Chatbot")
chat_btn = gr.Button("Add messages")

def chat(history):
time.sleep(2)
yield [["How are you?", "I am good."]]

chat_btn.click(
lambda history: history
+ [["How are you?", "I am good."]]
Expand Down
2 changes: 1 addition & 1 deletion gradio/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
matplotlib.use(self._original_backend)


def tex2svg(formula, *args):
def tex2svg(formula, *_args):
with MatplotlibBackendMananger():
import matplotlib.pyplot as plt

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ exclude = [

[tool.ruff]
extend-select = [
"ARG",
"B",
"C",
"E",
Expand Down

0 comments on commit f347fdc

Please sign in to comment.