From 3eb4f60ddf0c8236aff030850a1dd9b6805ad409 Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:44:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?refactor(typing):=20=E4=BD=BF=E7=94=A8Union?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E7=B1=BB=E5=9E=8B=E6=B3=A8=E8=A7=A3=E4=B8=AD?= =?UTF-8?q?=E7=9A=84|=E6=93=8D=E4=BD=9C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 统一使用Union类型注解以提高代码兼容性,特别是在旧版本Python中的支持 --- src/usepy/list/first.py | 7 +++++-- src/usepy/list/last.py | 5 +++-- src/usepy/list/sample.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/usepy/list/first.py b/src/usepy/list/first.py index fcb1415..8e73396 100644 --- a/src/usepy/list/first.py +++ b/src/usepy/list/first.py @@ -1,16 +1,19 @@ from typing import TypeVar, Sequence +from typing_ import Union + + T = TypeVar("T") -def first(array: Sequence[T]) -> T | None: +def first(array: Sequence[T]) -> Union[T, None]: """ Gets the first element of `array`. :param array: The array to query. :type array: Sequence[T] :return: Returns the first element of `array`. - :rtype: T | None + :rtype: Union[T, None] :Example: diff --git a/src/usepy/list/last.py b/src/usepy/list/last.py index 05ccbc1..6e3101a 100644 --- a/src/usepy/list/last.py +++ b/src/usepy/list/last.py @@ -1,16 +1,17 @@ from typing import TypeVar, Sequence +from typing_ import Union T = TypeVar("T") -def last(array: Sequence[T]) -> T | None: +def last(array: Sequence[T]) -> Union[T, None]: """ Gets the last element of `array`. :param array: The array to query. :type array: Sequence[T] :return: Returns the last element of `array`. - :rtype: T | None + :rtype: Union[T, None] :Example: diff --git a/src/usepy/list/sample.py b/src/usepy/list/sample.py index 1a8cb53..363aa21 100644 --- a/src/usepy/list/sample.py +++ b/src/usepy/list/sample.py @@ -1,10 +1,11 @@ import random from typing import TypeVar, Sequence +from typing_ import Union T = TypeVar("T") -def sample(arr: Sequence[T], count: int = 1) -> T | list[T]: +def sample(arr: Sequence[T], count: int = 1) -> Union[T, list[T]]: """ Returns a random element from a sequence. @@ -13,9 +14,10 @@ def sample(arr: Sequence[T], count: int = 1) -> T | list[T]: Args: arr (Sequence[T]): The sequence to sample from. + count (int, optional): The number of elements to sample. Defaults to 1. Returns: - T: A random element from the sequence. + Union[T, list[T]]: A random element from the sequence. Example: >>> sample([1, 2, 3, 4, 5]) From e3066dbf83f65c98da9bf289e7cba917769a7e5e Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:44:52 +0800 Subject: [PATCH 2/6] =?UTF-8?q?feat(typing):=20=E6=B7=BB=E5=8A=A0=E5=AF=B9?= =?UTF-8?q?=20Python=203.10=20=E4=BB=A5=E4=B8=8B=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9A=84=20Union=20=E7=B1=BB=E5=9E=8B=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/usepy/typing_.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/usepy/typing_.py diff --git a/src/usepy/typing_.py b/src/usepy/typing_.py new file mode 100644 index 0000000..9aa6ce4 --- /dev/null +++ b/src/usepy/typing_.py @@ -0,0 +1,7 @@ +import sys + + +if sys.version_info >= (3, 10): + from typing import Union +else: + from typing_extensions import Union From a43f2da9fd45d0d83c42056dd115833aca9622f9 Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:46:32 +0800 Subject: [PATCH 3/6] =?UTF-8?q?ci:=20=E5=8D=87=E7=BA=A7=20actions/cache=20?= =?UTF-8?q?=E4=BB=8E=20v2=20=E5=88=B0=20v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ce61952..80a6cab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: installer-parallel: true - name: Load cached venv id: cached-poetry-dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: .venv key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} @@ -40,4 +40,4 @@ jobs: - name: Run tests run: | source .venv/bin/activate - pytest tests/ \ No newline at end of file + pytest tests/ From b034d8bc5b92d8feaca89da3c5adf9364d9b67f6 Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:48:53 +0800 Subject: [PATCH 4/6] =?UTF-8?q?ci:=20=E6=9B=B4=E6=96=B0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=B8=AD=E7=9A=84Python=203.7?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=B8=BA3.7.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80a6cab..c215e62 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: fail-fast: true matrix: os: [ "ubuntu-latest" ] - python-version: [ "3.7", "3.8", "3.9", "3.10" ] + python-version: [ "3.7.1", "3.8", "3.9", "3.10" ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From abf750bbe67dcaa65b6e32fccb90d52133b39f3e Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:50:20 +0800 Subject: [PATCH 5/6] =?UTF-8?q?ci(workflows):=20=E7=A7=BB=E9=99=A4Python?= =?UTF-8?q?=203.7.1=E7=9A=84=E6=B5=8B=E8=AF=95=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c215e62..151d134 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: fail-fast: true matrix: os: [ "ubuntu-latest" ] - python-version: [ "3.7.1", "3.8", "3.9", "3.10" ] + python-version: [ "3.8", "3.9", "3.10" ] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 From 3d4a30d2606c2053e3fcdbaf6655dc07199fd81e Mon Sep 17 00:00:00 2001 From: miclon Date: Thu, 17 Jul 2025 09:53:29 +0800 Subject: [PATCH 6/6] =?UTF-8?q?build:=20=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8F=B7=E8=87=B30.4.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 31c9e0b..de675a7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "usepy" -version = "0.4.0" +version = "0.4.1" description = "usepy" homepage = "https://usepy.code05.com/" authors = ["miclon "]