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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix pyright unnecessary type ignore comment #1266

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions instructor/batch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Union, TypeVar, Optional
from collections.abc import Iterable
from pydantic import BaseModel, Field # type: ignore
from pydantic import BaseModel, Field
from instructor.process_response import handle_response_model
import instructor
import uuid
Expand Down Expand Up @@ -139,7 +139,7 @@ def create_from_messages(
"temperature": temperature,
"messages": messages,
**kwargs,
}
},
}
file.write(json.dumps(request) + "\n")
else:
Expand All @@ -159,6 +159,6 @@ def create_from_messages(
**kwargs,
),
method="POST",
url="/v1/chat/completions"
url="/v1/chat/completions",
)
file.write(batch_model.model_dump_json() + "\n")
2 changes: 1 addition & 1 deletion instructor/dsl/citation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, model_validator, ValidationInfo # type: ignore
from pydantic import BaseModel, Field, model_validator, ValidationInfo
from collections.abc import Generator


Expand Down
16 changes: 13 additions & 3 deletions instructor/dsl/iterable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Optional, cast, ClassVar
from collections.abc import AsyncGenerator, Generator, Iterable

from pydantic import BaseModel, Field, create_model # type: ignore
from pydantic import BaseModel, Field, create_model

from instructor.function_calls import OpenAISchema
from instructor.mode import Mode
Expand Down Expand Up @@ -109,7 +109,12 @@ def extract_json(
}:
if json_chunk := chunk.choices[0].delta.content:
yield json_chunk
elif mode in {Mode.TOOLS, Mode.TOOLS_STRICT, Mode.FIREWORKS_TOOLS, Mode.WRITER_TOOLS}:
elif mode in {
Mode.TOOLS,
Mode.TOOLS_STRICT,
Mode.FIREWORKS_TOOLS,
Mode.WRITER_TOOLS,
}:
if json_chunk := chunk.choices[0].delta.tool_calls:
if json_chunk[0].function.arguments is not None:
yield json_chunk[0].function.arguments
Expand Down Expand Up @@ -145,7 +150,12 @@ async def extract_json_async(
}:
if json_chunk := chunk.choices[0].delta.content:
yield json_chunk
elif mode in {Mode.TOOLS, Mode.TOOLS_STRICT, Mode.FIREWORKS_TOOLS, Mode.WRITER_TOOLS}:
elif mode in {
Mode.TOOLS,
Mode.TOOLS_STRICT,
Mode.FIREWORKS_TOOLS,
Mode.WRITER_TOOLS,
}:
if json_chunk := chunk.choices[0].delta.tool_calls:
if json_chunk[0].function.arguments is not None:
yield json_chunk[0].function.arguments
Expand Down
2 changes: 1 addition & 1 deletion instructor/dsl/maybe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, Field, create_model # type: ignore
from pydantic import BaseModel, Field, create_model
from typing import Generic, Optional, TypeVar

T = TypeVar("T", bound=BaseModel)
Expand Down
2 changes: 1 addition & 1 deletion instructor/dsl/validators.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Callable, Optional

from openai import OpenAI
from pydantic import Field # type: ignore
from pydantic import Field

from instructor.function_calls import OpenAISchema
from instructor.client import Instructor
Expand Down
22 changes: 10 additions & 12 deletions instructor/multimodal.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from urllib.parse import urlparse
import mimetypes
import requests
from pydantic import BaseModel, Field # type:ignore
from pydantic import BaseModel, Field
from .mode import Mode

F = TypeVar("F", bound=Callable[..., Any])
Expand Down Expand Up @@ -76,9 +76,7 @@
raise ValueError("Unable to determine image type or unsupported image format")

@classmethod
def autodetect_safely(
cls, source: str | Path
) -> Union[Image, str]: # noqa: UP007
def autodetect_safely(cls, source: str | Path) -> Union[Image, str]: # noqa: UP007
"""Safely attempt to autodetect an image from a source string or path.

Args:
Expand Down Expand Up @@ -210,9 +208,7 @@
class Audio(BaseModel):
"""Represents an audio that can be loaded from a URL or file path."""

source: str | Path = Field(
description="URL or file path of the audio"
) # noqa: UP007
source: str | Path = Field(description="URL or file path of the audio") # noqa: UP007
data: Union[str, None] = Field( # noqa: UP007
None, description="Base64 encoded audio data", repr=False
)
Expand Down Expand Up @@ -343,9 +339,7 @@
}
if autodetect_images:
if isinstance(content, list):
new_content: list[str | dict[str, Any] | Image | Audio] = (
[]
) # noqa: UP007
new_content: list[str | dict[str, Any] | Image | Audio] = [] # noqa: UP007
for item in content:
if isinstance(item, str):
new_content.append(Image.autodetect_safely(item))
Expand All @@ -365,8 +359,12 @@
cast(ImageParams, content)
)
if isinstance(content, str):
converted_messages.append({"role": role, "content": content, **other_kwargs}) # type: ignore
converted_messages.append(

Check failure on line 362 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)

Check failure on line 362 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)

Check failure on line 362 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.10)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)
{"role": role, "content": content, **other_kwargs}
) # type: ignore

Check failure on line 364 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

Check failure on line 364 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

Check failure on line 364 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.10)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
else:
converted_content = convert_contents(content, mode)
converted_messages.append({"role": role, "content": converted_content, **other_kwargs}) # type: ignore
converted_messages.append(

Check failure on line 367 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)

Check failure on line 367 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)

Check failure on line 367 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.10)

Type of "append" is partially unknown   Type of "append" is "(object: Unknown, /) -> None" (reportUnknownMemberType)
{"role": role, "content": converted_content, **other_kwargs}
) # type: ignore

Check failure on line 369 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (macos-latest, 3.11)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

Check failure on line 369 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.11)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)

Check failure on line 369 in instructor/multimodal.py

View workflow job for this annotation

GitHub Actions / Pyright (ubuntu-latest, 3.10)

Unnecessary "# type: ignore" comment (reportUnnecessaryTypeIgnoreComment)
return converted_messages # type: ignore
Loading