From 88d488b2981770b3ba7aaccaf6a232ff32e04531 Mon Sep 17 00:00:00 2001 From: AlexNg Date: Sun, 17 Mar 2024 22:50:38 +0800 Subject: [PATCH 1/2] fix: Fix function signature --- src/thread/_types.py | 5 +++++ src/thread/thread.py | 40 ++++++++++++++++------------------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/thread/_types.py b/src/thread/_types.py index 7f973ae..16ea67f 100644 --- a/src/thread/_types.py +++ b/src/thread/_types.py @@ -62,3 +62,8 @@ class SupportsGetItem(Protocol[_SupportsGetItem_T]): @runtime_checkable class SupportsLengthGetItem(Sized, Protocol[_SupportsGetItem_T]): __getitem__: Callable[..., _SupportsGetItem_T] + + +LengthLike_T = TypeVar('LengthLike_T', bound=SupportsLength) +GetLike_T = TypeVar('GetLike_T', bound=SupportsGetItem) +LengthandGetLike_T = TypeVar('LengthandGetLike_T', bound=SupportsLengthGetItem) diff --git a/src/thread/thread.py b/src/thread/thread.py index 6ec4cb5..24ef9af 100644 --- a/src/thread/thread.py +++ b/src/thread/thread.py @@ -36,6 +36,9 @@ class ParallelProcessing: ... SupportsLength, SupportsGetItem, SupportsLengthGetItem, + LengthLike_T, + GetLike_T, + LengthandGetLike_T, ) from typing_extensions import Generic from typing import ( @@ -369,15 +372,11 @@ class ParallelProcessing(Generic[_Target_P, _Target_T, _Dataset_T]): def __init__( self, function: DatasetFunction[_Dataset_T, _Target_P, _Target_T], - dataset: SupportsLengthGetItem[_Dataset_T], + dataset: LengthandGetLike_T, max_threads: int = 8, *overflow_args: Overflow_In, - _get_value: Optional[ - Callable[[SupportsLengthGetItem[_Dataset_T], int], _Dataset_T] - ] = None, - _length: Optional[ - Union[int, Callable[[SupportsLengthGetItem[_Dataset_T]], int]] - ] = None, + _get_value: Optional[Callable[[LengthandGetLike_T, int], _Dataset_T]] = None, + _length: Optional[Union[int, Callable[[Any], int]]] = None, **overflow_kwargs: Overflow_In, ) -> None: ... @@ -386,11 +385,11 @@ def __init__( def __init__( self, function: DatasetFunction[_Dataset_T, _Target_P, _Target_T], - dataset: SupportsLength, + dataset: LengthLike_T, max_threads: int = 8, *overflow_args: Overflow_In, - _get_value: Callable[[SupportsLength, int], _Dataset_T], - _length: Optional[Union[int, Callable[[SupportsLength], int]]] = None, + _get_value: Callable[[LengthLike_T, int], _Dataset_T], + _length: Optional[Union[int, Callable[[Any], int]]] = None, **overflow_kwargs: Overflow_In, ) -> None: ... @@ -399,13 +398,11 @@ def __init__( def __init__( self, function: DatasetFunction[_Dataset_T, _Target_P, _Target_T], - dataset: SupportsGetItem[_Dataset_T], + dataset: GetLike_T, max_threads: int = 8, *overflow_args: Overflow_In, - _get_value: Optional[ - Callable[[SupportsGetItem[_Dataset_T], int], _Dataset_T] - ] = None, - _length: Union[int, Callable[[SupportsGetItem[_Dataset_T]], int]], + _get_value: Optional[Callable[[GetLike_T, int], _Dataset_T]] = None, + _length: Union[int, Callable[[GetLike_T], int]], **overflow_kwargs: Overflow_In, ) -> None: ... @@ -435,18 +432,13 @@ def __init__( *overflow_args: Overflow_In, _get_value: Optional[ Union[ - Callable[[SupportsLengthGetItem[_Dataset_T], int], _Dataset_T], - Callable[[SupportsGetItem[_Dataset_T], int], _Dataset_T], - Callable[[SupportsLength, int], _Dataset_T], + Callable[[LengthLike_T, int], _Dataset_T], + Callable[[GetLike_T, int], _Dataset_T], + Callable[[LengthLike_T, int], _Dataset_T], Callable[[Any, int], _Dataset_T], ] ] = None, - _length: Optional[ - Union[ - int, - Callable[[Any], int], - ] - ] = None, + _length: Optional[Union[int, Callable[[Any], int]]] = None, **overflow_kwargs: Overflow_In, ) -> None: """ From 9f36b8462d08beffe0b6732facb5c7dee1199e3f Mon Sep 17 00:00:00 2001 From: AlexNg Date: Sun, 17 Mar 2024 22:53:16 +0800 Subject: [PATCH 2/2] chore: Increment version --- CITATION.cff | 10 +++++----- README.md | 2 +- pyproject.toml | 4 ++-- src/thread/__init__.py | 4 ++-- src/thread/_types.py | 2 +- src/thread/decorators/_processor.py | 2 +- src/thread/decorators/_threaded.py | 2 +- src/thread/exceptions.py | 2 +- src/thread/thread.py | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 9c3570a..ef70e38 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -9,11 +9,11 @@ identifiers: value: 10.5281/zenodo.10799219 description: This is the collection of archived snapshots of all versions of thread. - type: url - value: https://github.com/python-thread/thread/releases/tag/v1.1.0 - description: The GitHub release URL of tag v1.1.0. + value: https://github.com/python-thread/thread/releases/tag/v1.1.1 + description: The GitHub release URL of tag v1.1.1. - type: url - value: https://pypi.org/project/thread/1.1.0 - description: The PyPI release URL of tag v1.1.0. + value: https://pypi.org/project/thread/1.1.1 + description: The PyPI release URL of tag v1.1.1. cff-version: 1.2.0 date-released: 2024-03-07 keywords: @@ -32,6 +32,6 @@ repository-code: https://github.com/python-thread/thread repository-artifact: https://pypi.org/project/thread title: thread type: software -version: 1.1.0 +version: 1.1.1 url: https://thread.ngjx.org diff --git a/README.md b/README.md index dd695f4..e130d64 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ Our docs are [here!](https://thread.ngjx.org) ## Roadmap -- [x] v1.1.0 Release +- [x] v1.1.1 Release - [ ] Bug fixes - [ ] New features - [ ] Testing diff --git a/pyproject.toml b/pyproject.toml index af18e31..6e679dd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "thread" -version = "1.1.0" +version = "1.1.1" description = "Threading module extension" authors = ["Alex "] license = "BSD-3-Clause" @@ -30,7 +30,7 @@ classifiers = [ [tool.poetry.urls] Homepage = "https://thread.ngjx.org" -Documentation = "https://thread.ngjx.org/docs/v1.1.0" +Documentation = "https://thread.ngjx.org/docs/v1.1.1" Source = "https://github.com/python-thread/thread" Download = "https://pypi.org/project/thread/#files" "Release Notes" = "https://github.com/python-thread/thread/releases" diff --git a/src/thread/__init__.py b/src/thread/__init__.py index 0691236..2d7ac9a 100644 --- a/src/thread/__init__.py +++ b/src/thread/__init__.py @@ -1,6 +1,6 @@ """ ## Thread Library -Documentation at https://thread.ngjx.org/docs/v1.1.0 +Documentation at https://thread.ngjx.org/docs/v1.1.1 --- @@ -18,7 +18,7 @@ """ -__version__ = '1.1.0' +__version__ = '1.1.1' # Export Core diff --git a/src/thread/_types.py b/src/thread/_types.py index 16ea67f..98e0c8d 100644 --- a/src/thread/_types.py +++ b/src/thread/_types.py @@ -1,7 +1,7 @@ """ ## Types -Documentation: https://thread.ngjx.org/docs/v1.1.0 +Documentation: https://thread.ngjx.org/docs/v1.1.1 """ from typing import Any, Literal, Callable, Union, Sized diff --git a/src/thread/decorators/_processor.py b/src/thread/decorators/_processor.py index 55383a7..0131d69 100644 --- a/src/thread/decorators/_processor.py +++ b/src/thread/decorators/_processor.py @@ -1,7 +1,7 @@ """ ## Processor -Documentation: https://thread.ngjx.org/docs/v1.1.0 +Documentation: https://thread.ngjx.org/docs/v1.1.1 """ from functools import wraps diff --git a/src/thread/decorators/_threaded.py b/src/thread/decorators/_threaded.py index 06c14a3..4db6ef1 100644 --- a/src/thread/decorators/_threaded.py +++ b/src/thread/decorators/_threaded.py @@ -1,7 +1,7 @@ """ ## Threaded -Documentation: https://thread.ngjx.org/docs/v1.1.0 +Documentation: https://thread.ngjx.org/docs/v1.1.1 """ from functools import wraps diff --git a/src/thread/exceptions.py b/src/thread/exceptions.py index dcc3751..89ee6ae 100644 --- a/src/thread/exceptions.py +++ b/src/thread/exceptions.py @@ -1,7 +1,7 @@ """ ## Thread Exceptions -Documentation: https://thread.ngjx.org/docs/v1.1.0 +Documentation: https://thread.ngjx.org/docs/v1.1.1 """ import traceback diff --git a/src/thread/thread.py b/src/thread/thread.py index 24ef9af..893991f 100644 --- a/src/thread/thread.py +++ b/src/thread/thread.py @@ -8,7 +8,7 @@ class Thread: ... class ParallelProcessing: ... ``` -Documentation: https://thread.ngjx.org/docs/v1.1.0 +Documentation: https://thread.ngjx.org/docs/v1.1.1 """ import sys