Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ssl
from typing import Any
from typing import Any, Self

import httpx
from attrs import define, evolve, field
Expand Down Expand Up @@ -65,7 +65,7 @@ def with_timeout(self, timeout: httpx.Timeout) -> "Client":
self._async_client.timeout = timeout
return evolve(self, timeout=timeout)

def set_httpx_client(self, client: httpx.Client) -> "Client":
def set_httpx_client(self, client: httpx.Client) -> Self:
"""Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -87,7 +87,7 @@ def get_httpx_client(self) -> httpx.Client:
)
return self._client

def __enter__(self) -> "Client":
def __enter__(self) -> Self:
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
self.get_httpx_client().__enter__()
return self
Expand All @@ -96,7 +96,7 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None:
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
self.get_httpx_client().__exit__(*args, **kwargs)

def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
"""Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -118,7 +118,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient:
)
return self._async_client

async def __aenter__(self) -> "Client":
async def __aenter__(self) -> Self:
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
await self.get_async_httpx_client().__aenter__()
return self
Expand Down Expand Up @@ -195,7 +195,7 @@ def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
self._async_client.timeout = timeout
return evolve(self, timeout=timeout)

def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
def set_httpx_client(self, client: httpx.Client) -> Self:
"""Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -218,7 +218,7 @@ def get_httpx_client(self) -> httpx.Client:
)
return self._client

def __enter__(self) -> "AuthenticatedClient":
def __enter__(self) -> Self:
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
self.get_httpx_client().__enter__()
return self
Expand All @@ -227,7 +227,7 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None:
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
self.get_httpx_client().__exit__(*args, **kwargs)

def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
"""Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -250,7 +250,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient:
)
return self._async_client

async def __aenter__(self) -> "AuthenticatedClient":
async def __aenter__(self) -> Self:
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
await self.get_async_httpx_client().__aenter__()
return self
Expand Down
4 changes: 2 additions & 2 deletions end_to_end_tests/generated_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
import sys
import tempfile
from typing import Any
from typing import Any, Self

from attrs import define
import pytest
Expand All @@ -29,7 +29,7 @@ class GeneratedClientContext:
monkeypatch: pytest.MonkeyPatch
old_modules: set[str] | None = None

def __enter__(self) -> "GeneratedClientContext":
def __enter__(self) -> Self:
self.monkeypatch.syspath_prepend(self.output_path)
self.old_modules = set(sys.modules.keys())
return self
Expand Down
18 changes: 9 additions & 9 deletions end_to_end_tests/golden-record/my_test_api_client/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ssl
from typing import Any
from typing import Any, Self

import httpx
from attrs import define, evolve, field
Expand Down Expand Up @@ -69,7 +69,7 @@ def with_timeout(self, timeout: httpx.Timeout) -> "Client":
self._async_client.timeout = timeout
return evolve(self, timeout=timeout)

def set_httpx_client(self, client: httpx.Client) -> "Client":
def set_httpx_client(self, client: httpx.Client) -> Self:
"""Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -91,7 +91,7 @@ def get_httpx_client(self) -> httpx.Client:
)
return self._client

def __enter__(self) -> "Client":
def __enter__(self) -> Self:
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
self.get_httpx_client().__enter__()
return self
Expand All @@ -100,7 +100,7 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None:
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
self.get_httpx_client().__exit__(*args, **kwargs)

def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "Client":
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
"""Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -122,7 +122,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient:
)
return self._async_client

async def __aenter__(self) -> "Client":
async def __aenter__(self) -> Self:
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
await self.get_async_httpx_client().__aenter__()
return self
Expand Down Expand Up @@ -203,7 +203,7 @@ def with_timeout(self, timeout: httpx.Timeout) -> "AuthenticatedClient":
self._async_client.timeout = timeout
return evolve(self, timeout=timeout)

def set_httpx_client(self, client: httpx.Client) -> "AuthenticatedClient":
def set_httpx_client(self, client: httpx.Client) -> Self:
"""Manually set the underlying httpx.Client

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -226,7 +226,7 @@ def get_httpx_client(self) -> httpx.Client:
)
return self._client

def __enter__(self) -> "AuthenticatedClient":
def __enter__(self) -> Self:
"""Enter a context manager for self.client—you cannot enter twice (see httpx docs)"""
self.get_httpx_client().__enter__()
return self
Expand All @@ -235,7 +235,7 @@ def __exit__(self, *args: Any, **kwargs: Any) -> None:
"""Exit a context manager for internal httpx.Client (see httpx docs)"""
self.get_httpx_client().__exit__(*args, **kwargs)

def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> "AuthenticatedClient":
def set_async_httpx_client(self, async_client: httpx.AsyncClient) -> Self:
"""Manually set the underlying httpx.AsyncClient

**NOTE**: This will override any other settings on the client, including cookies, headers, and timeout.
Expand All @@ -258,7 +258,7 @@ def get_async_httpx_client(self) -> httpx.AsyncClient:
)
return self._async_client

async def __aenter__(self) -> "AuthenticatedClient":
async def __aenter__(self) -> Self:
"""Enter a context manager for underlying httpx.AsyncClient—you cannot enter twice (see httpx docs)"""
await self.get_async_httpx_client().__aenter__()
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class AModel:
not_required_nullable_model: ModelWithUnionProperty | None | Unset = UNSET

def to_dict(self) -> dict[str, Any]:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty
from ..models.free_form_model import FreeFormModel # noqa: PLC0415
from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415

an_enum_value = self.an_enum_value.value

Expand Down Expand Up @@ -256,8 +256,8 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty
from ..models.free_form_model import FreeFormModel # noqa: PLC0415
from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415

d = dict(src_dict)
an_enum_value = AnEnum(d.pop("an_enum_value"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class AnAllOfEnum(str, Enum):
class AnAllOfEnum(StrEnum):
A_DEFAULT = "a_default"
BAR = "bar"
FOO = "foo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def to_dict(self) -> dict[str, Any]:
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_b_item import (
AnArrayWithACircularRefInItemsObjectBItem,
AnArrayWithACircularRefInItemsObjectBItem, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_dict(self) -> dict[str, Any]:
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_b_item import (
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem,
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_dict(self) -> dict[str, Any]:
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_additional_properties_a_item import (
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem,
AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def to_dict(self) -> dict[str, Any]:
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.an_array_with_a_circular_ref_in_items_object_a_item import (
AnArrayWithACircularRefInItemsObjectAItem,
AnArrayWithACircularRefInItemsObjectAItem, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class AnEnum(str, Enum):
class AnEnum(StrEnum):
FIRST_VALUE = "FIRST_VALUE"
SECOND_VALUE = "SECOND_VALUE"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class AnEnumWithNull(str, Enum):
class AnEnumWithNull(StrEnum):
FIRST_VALUE = "FIRST_VALUE"
SECOND_VALUE = "SECOND_VALUE"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class AnotherAllOfSubModelType(str, Enum):
class AnotherAllOfSubModelType(StrEnum):
SUBMODEL = "submodel"

def __str__(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BodyUploadFileTestsUploadPost:

def to_dict(self) -> dict[str, Any]:
from ..models.body_upload_file_tests_upload_post_some_nullable_object import (
BodyUploadFileTestsUploadPostSomeNullableObject,
BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415
)

some_file = self.some_file.to_tuple()
Expand Down Expand Up @@ -172,7 +172,7 @@ def to_dict(self) -> dict[str, Any]:

def to_multipart(self) -> types.RequestFiles:
from ..models.body_upload_file_tests_upload_post_some_nullable_object import (
BodyUploadFileTestsUploadPostSomeNullableObject,
BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415
)

files: types.RequestFiles = []
Expand Down Expand Up @@ -251,16 +251,18 @@ def to_multipart(self) -> types.RequestFiles:

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.a_form_data import AFormData
from ..models.a_form_data import AFormData # noqa: PLC0415
from ..models.body_upload_file_tests_upload_post_additional_property import (
BodyUploadFileTestsUploadPostAdditionalProperty,
BodyUploadFileTestsUploadPostAdditionalProperty, # noqa: PLC0415
)
from ..models.body_upload_file_tests_upload_post_some_nullable_object import (
BodyUploadFileTestsUploadPostSomeNullableObject,
BodyUploadFileTestsUploadPostSomeNullableObject, # noqa: PLC0415
)
from ..models.body_upload_file_tests_upload_post_some_object import (
BodyUploadFileTestsUploadPostSomeObject, # noqa: PLC0415
)
from ..models.body_upload_file_tests_upload_post_some_object import BodyUploadFileTestsUploadPostSomeObject
from ..models.body_upload_file_tests_upload_post_some_optional_object import (
BodyUploadFileTestsUploadPostSomeOptionalObject,
BodyUploadFileTestsUploadPostSomeOptionalObject, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class DifferentEnum(str, Enum):
class DifferentEnum(StrEnum):
DIFFERENT = "DIFFERENT"
OTHER = "OTHER"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Extended:
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

def to_dict(self) -> dict[str, Any]:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty
from ..models.free_form_model import FreeFormModel # noqa: PLC0415
from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415

an_enum_value = self.an_enum_value.value

Expand Down Expand Up @@ -263,8 +263,8 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.free_form_model import FreeFormModel
from ..models.model_with_union_property import ModelWithUnionProperty
from ..models.free_form_model import FreeFormModel # noqa: PLC0415
from ..models.model_with_union_property import ModelWithUnionProperty # noqa: PLC0415

d = dict(src_dict)
an_enum_value = AnEnum(d.pop("an_enum_value"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum
from enum import StrEnum


class GetLocationHeaderTypesStringEnumHeader(str, Enum):
class GetLocationHeaderTypesStringEnumHeader(StrEnum):
ONE = "one"
THREE = "three"
TWO = "two"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.a_model import AModel
from ..models.extended import Extended
from ..models.a_model import AModel # noqa: PLC0415
from ..models.extended import Extended # noqa: PLC0415

d = dict(src_dict)
_aliased = d.pop("aliased", UNSET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def to_dict(self) -> dict[str, Any]:

@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.validation_error import ValidationError
from ..models.validation_error import ValidationError # noqa: PLC0415

d = dict(src_dict)
_detail = d.pop("detail", UNSET)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def to_dict(self) -> dict[str, Any]:
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.model_with_additional_properties_inlined_additional_property import (
ModelWithAdditionalPropertiesInlinedAdditionalProperty,
ModelWithAdditionalPropertiesInlinedAdditionalProperty, # noqa: PLC0415
)

d = dict(src_dict)
Expand Down
Loading