Skip to content
Open
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
Expand Up @@ -30,7 +30,7 @@ To be able to use it, you will need these dependencies in your own package that
* python-dateutil >= 2.8.2
{{#async}}
* aiohttp >= 3.8.4
* aiohttp-retry >= 2.8.3
* aiohttp-retry >= 2.8.3 (only when retries are configured)
{{/async}}
{{#hasHttpSignatureMethods}}
* pem >= 19.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import io
import json
import re
import ssl
from typing import Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Optional, Union

import aiohttp
import aiohttp_retry
from multidict import CIMultiDict

from {{packageName}}.exceptions import ApiException, ApiValueError

if TYPE_CHECKING:
import aiohttp_retry

RESTResponseType = aiohttp.ClientResponse

ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'})
Expand Down Expand Up @@ -76,20 +78,23 @@ class RESTClientObject:
retries = configuration.retries
if retries is None:
self._effective_retry_options = None
elif isinstance(retries, aiohttp_retry.RetryOptionsBase):
self._effective_retry_options = retries
elif isinstance(retries, int):
self._effective_retry_options = aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
else:
self._effective_retry_options = None
import aiohttp_retry

if isinstance(retries, aiohttp_retry.RetryOptionsBase):
self._effective_retry_options = retries
elif isinstance(retries, int):
self._effective_retry_options = aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
else:
self._effective_retry_options = None

self.pool_manager: Optional[aiohttp.ClientSession] = None
self.retry_client: Optional[aiohttp_retry.RetryClient] = None
self.retry_client: Optional["aiohttp_retry.RetryClient"] = None

async def close(self) -> None:
if self.pool_manager:
Expand Down Expand Up @@ -256,7 +261,7 @@ class RESTClientObject:
declared content type."""
raise ApiException(status=0, reason=msg)

pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
pool_manager: Union[aiohttp.ClientSession, "aiohttp_retry.RetryClient"]

# https pool manager
if self.pool_manager is None:
Expand All @@ -265,6 +270,8 @@ class RESTClientObject:

if self._effective_retry_options is not None and method in ALLOW_RETRY_METHODS:
if self.retry_client is None:
import aiohttp_retry

self.retry_client = aiohttp_retry.RetryClient(
client_session=self.pool_manager,
retry_options=self._effective_retry_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

{{#asyncio}}
import aiohttp
import aiohttp_retry
{{/asyncio}}
{{#async}}
import base64
Expand All @@ -24,6 +23,13 @@ from urllib.parse import urlparse
from urllib.request import getproxies
{{/async}}
from typing_extensions import NotRequired, Self
{{#asyncio}}

from typing import TYPE_CHECKING

if TYPE_CHECKING:
import aiohttp_retry
{{/asyncio}}

{{^async}}
import urllib3
Expand Down Expand Up @@ -344,7 +350,7 @@ conf = {{{packageName}}}.Configuration(
ignore_operation_servers: bool=False,
ssl_ca_cert: Optional[str]=None,
{{#asyncio}}
retries: Optional[Union[int, aiohttp_retry.RetryOptionsBase]] = None,
retries: Optional[Union[int, "aiohttp_retry.RetryOptionsBase"]] = None,
Comment thread
timonrieger marked this conversation as resolved.
Resolved
trace_configs: Optional[List[aiohttp.TraceConfig]] = None,
tcp_connector_limit_per_host: Optional[int] = None,
client_session_kwargs: Optional[Dict[str, Any]] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ urllib3 = ">= 2.7.0, < 3.0.0"
python-dateutil = ">= 2.8.2"
{{#asyncio}}
aiohttp = ">= 3.14.1"
aiohttp-retry = ">= 2.8.3"
aiohttp-retry = { version = ">= 2.8.3", optional = true }
{{/asyncio}}
{{#httpx}}
httpx = ">= 0.28.1"
Expand All @@ -58,6 +58,11 @@ pycryptodome = ">= 3.9.0"
{{/hasHttpSignatureMethods}}
pydantic = ">= 2.11"
typing-extensions = ">= 4.7.1"
{{#asyncio}}

[tool.poetry.extras]
retry = ["aiohttp-retry"]
{{/asyncio}}
{{/poetry1}}
{{^poetry1}}
requires-python = ">=3.11"
Expand All @@ -75,7 +80,6 @@ dependencies = [
{{/httpx2}}
{{#asyncio}}
"aiohttp (>=3.14.1)",
"aiohttp-retry (>=2.8.3)",
{{/asyncio}}
{{#hasHttpSignatureMethods}}
"pem (>=19.3.0)",
Expand All @@ -84,6 +88,11 @@ dependencies = [
"pydantic (>=2.11)",
"typing-extensions (>=4.7.1)",
]
{{#asyncio}}

[project.optional-dependencies]
retry = ["aiohttp-retry (>=2.8.3)"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The generated README's install commands do not select this extra. Users who configure retries then hit ModuleNotFoundError; document the [retry] install command.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/python/pyproject.mustache, line 94:

<comment>The generated README's install commands do not select this extra. Users who configure retries then hit `ModuleNotFoundError`; document the `[retry]` install command.</comment>

<file context>
@@ -84,6 +88,11 @@ dependencies = [
+{{#asyncio}}
+
+[project.optional-dependencies]
+retry = ["aiohttp-retry (>=2.8.3)"]
+{{/asyncio}}
 
</file context>

{{/asyncio}}

[project.urls]
Repository = "https://{{{gitHost}}}/{{{gitUserId}}}/{{{gitRepoId}}}"
Expand All @@ -98,6 +107,9 @@ tox = ">= 3.9.0"
flake8 = ">= 4.0.0"
types-python-dateutil = ">= 2.8.19.14"
mypy = ">= 1.5"
{{#asyncio}}
aiohttp-retry = ">= 2.8.3"
{{/asyncio}}
{{/poetry1}}
{{^poetry1}}
[dependency-groups]
Expand All @@ -108,6 +120,9 @@ dev = [
"flake8>=4.0.0",
"types-python-dateutil>=2.8.19.14",
"mypy>=1.5",
{{#asyncio}}
"aiohttp-retry>=2.8.3",
{{/asyncio}}
]
{{/poetry1}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ urllib3 >= 2.7.0, < 3.0.0
python_dateutil >= 2.8.2
{{#asyncio}}
aiohttp >= 3.14.1
aiohttp-retry >= 2.8.3
{{/asyncio}}
{{#httpx}}
httpx >= 0.28.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ REQUIRES = [
"python-dateutil >= 2.8.2",
{{#asyncio}}
"aiohttp >= 3.14.1",
"aiohttp-retry >= 2.8.3",
{{/asyncio}}
{{#httpx}}
"httpx >= 0.28.1",
Expand All @@ -43,6 +42,9 @@ setup(
url="{{packageUrl}}",
keywords=["OpenAPI", "OpenAPI-Generator", "{{{appName}}}"],
install_requires=REQUIRES,
{{#asyncio}}
extras_require={"retry": ["aiohttp-retry >= 2.8.3"]},
{{/asyncio}}
{{#sourceFolder}}
package_dir={"": "{{{sourceFolder}}}"},
{{/sourceFolder}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ tox >= 3.9.0
flake8 >= 4.0.0
types-python-dateutil >= 2.8.19.14
mypy >= 1.5
{{#asyncio}}
aiohttp-retry >= 2.8.3
{{/asyncio}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

Comment thread
timonrieger marked this conversation as resolved.
Resolved

import aiohttp
import aiohttp_retry
import base64
import copy
import http.client as httplib
Expand All @@ -21,6 +20,11 @@
from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
from typing_extensions import NotRequired, Self

from typing import TYPE_CHECKING

if TYPE_CHECKING:
import aiohttp_retry


from petstore_api.signing import HttpSigningConfiguration

Expand Down Expand Up @@ -288,7 +292,7 @@ def __init__(
server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
ignore_operation_servers: bool=False,
ssl_ca_cert: Optional[str]=None,
retries: Optional[Union[int, aiohttp_retry.RetryOptionsBase]] = None,
retries: Optional[Union[int, "aiohttp_retry.RetryOptionsBase"]] = None,
trace_configs: Optional[List[aiohttp.TraceConfig]] = None,
tcp_connector_limit_per_host: Optional[int] = None,
client_session_kwargs: Optional[Dict[str, Any]] = None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
import json
import re
import ssl
from typing import Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Optional, Union

import aiohttp
import aiohttp_retry
from multidict import CIMultiDict

from petstore_api.exceptions import ApiException, ApiValueError

if TYPE_CHECKING:
import aiohttp_retry

RESTResponseType = aiohttp.ClientResponse

ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'})
Expand Down Expand Up @@ -85,20 +87,23 @@ def __init__(self, configuration) -> None:
retries = configuration.retries
if retries is None:
self._effective_retry_options = None
elif isinstance(retries, aiohttp_retry.RetryOptionsBase):
self._effective_retry_options = retries
elif isinstance(retries, int):
self._effective_retry_options = aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
else:
self._effective_retry_options = None
import aiohttp_retry

if isinstance(retries, aiohttp_retry.RetryOptionsBase):
self._effective_retry_options = retries
elif isinstance(retries, int):
self._effective_retry_options = aiohttp_retry.ExponentialRetry(
attempts=retries,
factor=2.0,
start_timeout=0.1,
max_timeout=120.0
)
else:
self._effective_retry_options = None

self.pool_manager: Optional[aiohttp.ClientSession] = None
self.retry_client: Optional[aiohttp_retry.RetryClient] = None
self.retry_client: Optional["aiohttp_retry.RetryClient"] = None

async def close(self) -> None:
if self.pool_manager:
Expand Down Expand Up @@ -258,7 +263,7 @@ async def request(
declared content type."""
raise ApiException(status=0, reason=msg)

pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
pool_manager: Union[aiohttp.ClientSession, "aiohttp_retry.RetryClient"]

# https pool manager
if self.pool_manager is None:
Expand All @@ -267,6 +272,8 @@ async def request(

if self._effective_retry_options is not None and method in ALLOW_RETRY_METHODS:
if self.retry_client is None:
import aiohttp_retry

self.retry_client = aiohttp_retry.RetryClient(
client_session=self.pool_manager,
retry_options=self._effective_retry_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ include = ["petstore_api/py.typed"]
python = "^3.11"
python-dateutil = ">= 2.8.2"
aiohttp = ">= 3.14.1"
aiohttp-retry = ">= 2.8.3"
aiohttp-retry = { version = ">= 2.8.3", optional = true }
pem = ">= 19.3.0"
pycryptodome = ">= 3.9.0"
pydantic = ">= 2.11"
typing-extensions = ">= 4.7.1"

[tool.poetry.extras]
retry = ["aiohttp-retry"]
# Deprecated by Poetry; retained for compatibility with legacy Poetry 1 releases.
[tool.poetry.dev-dependencies]
pytest = ">= 9.0.3"
Expand All @@ -26,6 +29,7 @@ tox = ">= 3.9.0"
flake8 = ">= 4.0.0"
types-python-dateutil = ">= 2.8.19.14"
mypy = ">= 1.5"
aiohttp-retry = ">= 2.8.3"


[build-system]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
python_dateutil >= 2.8.2
aiohttp >= 3.14.1
aiohttp-retry >= 2.8.3
pem >= 19.3.0
pycryptodome >= 3.9.0
pydantic >= 2.11
Expand Down
2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/python-aiohttp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
REQUIRES = [
"python-dateutil >= 2.8.2",
"aiohttp >= 3.14.1",
"aiohttp-retry >= 2.8.3",
"pem >= 19.3.0",
"pycryptodome >= 3.9.0",
"pydantic >= 2.11",
Expand All @@ -40,6 +39,7 @@
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "OpenAPI Petstore"],
install_requires=REQUIRES,
extras_require={"retry": ["aiohttp-retry >= 2.8.3"]},
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,
license="Apache-2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tox >= 3.9.0
flake8 >= 4.0.0
types-python-dateutil >= 2.8.19.14
mypy >= 1.5
aiohttp-retry >= 2.8.3
Loading