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

👨‍💻 Update 2.0.0 #28

Merged
merged 43 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d976ed1
refactor: Simplify TranslatedObject class and remove license header
DavideGalilei Dec 3, 2024
fbdafeb
refactor: Improve type hints and add docstrings to exceptions and tra…
DavideGalilei Dec 3, 2024
910cdca
refactor: Simplify base translator module by removing license header
DavideGalilei Dec 3, 2024
c1f2a54
refactor: Convert TranslatedObject to dataclass with improved type sa…
DavideGalilei Dec 3, 2024
4c8d65e
refactor: Improve proxy handling and add type hints in translator cla…
DavideGalilei Dec 3, 2024
7375acd
fix: Resolve mypy type hint errors in gpytranslate library
DavideGalilei Dec 3, 2024
ea857df
refactor: Fix type hints and variable references in gpytranslate
DavideGalilei Dec 3, 2024
116bb14
refactor: Update type hints to use typing.Callable for headers parameter
DavideGalilei Dec 3, 2024
9144e4d
style: Format code with consistent trailing commas and quotes
DavideGalilei Dec 3, 2024
6ec5714
fix: Resolve mypy type checking errors in gpytranslate library
DavideGalilei Dec 3, 2024
286aede
refactor: Fix undefined variable names in translation methods
DavideGalilei Dec 3, 2024
5552b97
fix: Resolve mypy type checking errors in gpytranslate module
DavideGalilei Dec 3, 2024
75a7f9b
refactor: Fix undefined variable names in async and sync translators
DavideGalilei Dec 3, 2024
30f04e4
refactor: Simplify imports and user agent header generation
DavideGalilei Dec 3, 2024
b0d4e92
refactor: Add type annotations for generic types in types module
DavideGalilei Dec 3, 2024
8d9498c
refactor: Simplify method signatures and remove unnecessary whitespace
DavideGalilei Dec 3, 2024
fce45b1
refactor: Add type annotations for generic types in base translator
DavideGalilei Dec 3, 2024
0778a34
refactor: Remove license headers from multiple files
DavideGalilei Dec 3, 2024
88ed2a8
feat: Add return type annotations to test and example functions
DavideGalilei Dec 3, 2024
0857a45
refactor: Rename client to http_client and remove redundant import
DavideGalilei Dec 3, 2024
425ad9e
refactor: Add type annotations and type variables to improve type che…
DavideGalilei Dec 3, 2024
625e447
feat: Add typing_extensions import for TypedDict compatibility
DavideGalilei Dec 3, 2024
87e22f6
refactor: Add type annotations to resolve mypy type checking errors
DavideGalilei Dec 3, 2024
ea0d381
refactor: Add type annotations to improve type checking in gpytranslate
DavideGalilei Dec 3, 2024
3622bce
refactor: Add type annotations and fix type checking issues
DavideGalilei Dec 3, 2024
660b6ec
refactor: Add type annotations for Mapping and List in gpytranslate a…
DavideGalilei Dec 3, 2024
15b448a
refactor: Add type annotations to functions in gpytranslate and sync_…
DavideGalilei Dec 3, 2024
2afc6e2
refactor: Add type annotations and improve httpx client configuration
DavideGalilei Dec 3, 2024
997bb60
feat: Add Tuple import to resolve undefined name errors
DavideGalilei Dec 3, 2024
b7dbaab
refactor: Remove TranslatorOptions TypedDict and simplify client options
DavideGalilei Dec 3, 2024
f97f27a
style: Add type annotations for **extra kwargs in translation methods
DavideGalilei Dec 3, 2024
3dca281
fix: Add type annotation for **extra in tts() method
DavideGalilei Dec 3, 2024
99918f2
build: Migrate from hatchling to poetry and update project configuration
DavideGalilei Dec 3, 2024
fd9e231
feat: Add pytest configuration options to pyproject.toml
DavideGalilei Dec 3, 2024
151eb39
docs: Add docstrings and improve code documentation
DavideGalilei Dec 3, 2024
c8ccff8
docs: Add docstrings to test functions for improved code documentation
DavideGalilei Dec 3, 2024
b524038
style: Format code with improved readability and consistent style
DavideGalilei Dec 3, 2024
4f780ed
refactor: Improve code quality with better docstrings, error messages…
DavideGalilei Dec 3, 2024
440305d
refactor: Remove unused imports and clean up type definitions
DavideGalilei Dec 3, 2024
ae12c90
refactor: Improve code quality with docstrings, type hints, and valid…
DavideGalilei Dec 3, 2024
2533ee0
refactor: Fix TTS method signature and documentation in Translator class
DavideGalilei Dec 3, 2024
d9471e0
docs: Add badges, language codes, error handling, and contributing gu…
DavideGalilei Dec 3, 2024
ea14253
👨‍💻 Update 2.0.0
DavideGalilei Dec 3, 2024
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
Prev Previous commit
Next Next commit
refactor: Remove TranslatorOptions TypedDict and simplify client options
  • Loading branch information
DavideGalilei committed Dec 3, 2024
commit b7dbaabdaa8ac46f3cc35dd97834c1027d424d8f
22 changes: 2 additions & 20 deletions gpytranslate/gpytranslate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import io
from collections.abc import Mapping
from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple, TypeVar, Union, overload
from typing_extensions import TypedDict

import httpx

from .exceptions import TranslationError
Expand All @@ -25,21 +23,6 @@ async def close(self) -> None: ...

from httpx import Auth, Limits, Proxy, Timeout, URL

class TranslatorOptions(TypedDict, total=False):
auth: Optional[Union[Tuple[str, str], Auth]]
params: Optional[Dict[str, Any]]
headers: Optional[Dict[str, str]]
cookies: Optional[Dict[str, str]]
verify: Union[bool, str]
cert: Optional[Union[str, Tuple[str, str]]]
http1: bool
http2: bool
proxies: Optional[Union[str, Proxy]]
timeout: Optional[Union[float, Timeout]]
limits: Optional[Limits]
max_redirects: int
trust_env: bool


class Translator(BaseTranslator):
def __init__(
Expand All @@ -48,7 +31,7 @@ def __init__(
url: str = DEFAULT_TRANSLATION_ENDPOINT,
tts_url: str = DEFAULT_TTS_ENDPOINT,
headers: Optional[Union[Dict[str, str], Callable[[], Dict[str, str]]]] = None,
**options: TranslatorOptions,
**options: Any,
) -> None:
self.url = url
self.tts_url = tts_url
Expand Down Expand Up @@ -168,8 +151,7 @@ async def translate(
if proxies.get("socks5h"):
proxies["socks5h"] = httpx.AsyncHTTPTransport(proxy=self.proxies["socks5h"])

client_options = {k: v for k, v in self.options.items() if k in TranslatorOptions.__annotations__}
async with httpx.AsyncClient(mounts=proxies, **client_options) as http_client:
async with httpx.AsyncClient(mounts=proxies, **self.options) as http_client:
raw: Union[Mapping[str, Any], List[Any]] = (
(
await http_client.post(
Expand Down
7 changes: 2 additions & 5 deletions gpytranslate/sync/sync_translator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from collections.abc import Mapping
from typing import Any, BinaryIO, Callable, Dict, List, Optional, TypeVar, Union, overload

from ..gpytranslate import TranslatorOptions

import httpx

from ..exceptions import TranslationError
Expand All @@ -24,7 +22,7 @@ def __init__(
url: str = DEFAULT_TRANSLATION_ENDPOINT,
tts_url: str = DEFAULT_TTS_ENDPOINT,
headers: Optional[Union[Dict[str, str], Callable[[], Dict[str, str]]]] = None,
**options: TranslatorOptions,
**options: Any,
) -> None:
self.url = url
self.tts_url = tts_url
Expand Down Expand Up @@ -143,8 +141,7 @@ def translate(
if proxies.get("socks5h"):
proxies["socks5h"] = httpx.HTTPTransport(proxy=self.proxies["socks5h"])

client_options = {k: v for k, v in self.options.items() if k in TranslatorOptions.__annotations__}
with httpx.Client(mounts=proxies, **client_options) as c:
with httpx.Client(mounts=proxies, **self.options) as c:
raw: Union[Mapping[str, Any], List[Any]] = (
c.post(
self.url,
Expand Down