Skip to content

Commit

Permalink
Merge branch 'python-3.12'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anvil committed Nov 25, 2023
2 parents ae67a97 + 435f8cf commit d11de3b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## [Unreleased]

### Add
- Add python 3.12 support

### Fixed
- Fix Context and _ContextIterator type thing

## [0.10.2] - 2023-05-29

### Changed
Expand Down
11 changes: 6 additions & 5 deletions kaioretry/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
import logging
import uuid

from typing import cast, Awaitable, Any, TypeVar
from typing import cast, Awaitable, Any, TypeVar, Generic
from collections.abc import Callable, Generator, AsyncGenerator

from .types import NonNegative, Number, UpdateDelayFunc
Expand All @@ -103,14 +103,15 @@
SleepF = Callable[[Number], SleepRetVal]


class _ContextIterator:
class _ContextIterator(Generic[SleepRetVal]):
"""Single-usage helper class for Context objects."""

# pylint: disable=too-few-public-methods

def __init__(self, identifier: uuid.UUID, sleep: SleepF[Any], tries: int,
delay: NonNegative, update_delay: UpdateDelayFunc,
logger: logging.Logger, /) -> None:
# pylint: disable=too-many-arguments
self.__identifier = identifier
self.__sleep = sleep
self.__delay = delay
Expand Down Expand Up @@ -189,6 +190,7 @@ def __init__(self, /, tries: int = -1, delay: NonNegative = 0, *,
max_delay: NonNegative | None = None,
min_delay: NonNegative = 0,
logger: logging.Logger = DEFAULT_LOGGER) -> None:
# pylint: disable=too-many-arguments
if tries == 0:
raise ValueError("tries value cannot be 0")
self.__tries = tries
Expand Down Expand Up @@ -223,7 +225,7 @@ def __update_delay(self, delay: NonNegative) -> NonNegative:
return delay

def __make_iterator(
self, sleep: SleepF[Any]) -> Generator[SleepRetVal, None, None]:
self, sleep: SleepF[SleepRetVal]) -> Generator[SleepRetVal, None, None]:
return iter(_ContextIterator(
uuid.uuid4(), sleep, self.__tries, self.__delay,
self.__update_delay, self.__logger))
Expand All @@ -234,8 +236,7 @@ def __iter__(self) -> Generator[None, None, None]:

async def __aiter__(self) -> AsyncGenerator[None, None]:
yield
for sleep in cast(Generator[Awaitable[None], None, None],
self.__make_iterator(asyncio.sleep)):
for sleep in self.__make_iterator(asyncio.sleep):
await sleep
yield

Expand Down
10 changes: 7 additions & 3 deletions kaioretry/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ def __success(self, func: Function) -> None:
self.__log(
logging.INFO, "%s has succesfully completed", func.__name__)

# pylint: disable=inconsistent-return-statements
def __retry(self, func: Callable[FuncParam, FuncRetVal],
*args: FuncParam.args,
**kwargs: FuncParam.kwargs) -> FuncRetVal:
# pylint: disable=inconsistent-return-statements
# For some reason, pylint and python 3.12 seem to raise false
# positives no-members warnings on ParamSpec.
# pylint: disable=no-member
for _ in self.__context:
try:
result = func(*args, **kwargs)
Expand Down Expand Up @@ -206,6 +209,8 @@ async def __aioretry(
Callable[FuncParam, FuncRetVal],
*args: FuncParam.args,
**kwargs: FuncParam.kwargs) -> FuncRetVal:
# See above.
# pylint: disable=no-member
async for _ in self.__context:
try:
result = func(*args, **kwargs)
Expand Down Expand Up @@ -290,8 +295,7 @@ def is_func_async(cls, func: Function) -> bool:
def __call__(self, func: Callable[FuncParam, FuncRetVal]) \
-> Callable[FuncParam, FuncRetVal]:
if self.is_func_async(func):
return self.aioretry(
cast(Callable[FuncParam, Awaitable[Any]], func))
return cast(Callable[FuncParam, FuncRetVal], self.aioretry(func))
return self.retry(func)

def __str__(self) -> str:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers = [
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development"
Expand Down

0 comments on commit d11de3b

Please sign in to comment.