Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand All @@ -40,4 +40,4 @@ jobs:
- name: Run tests
run: |
source .venv/bin/activate
pytest tests/
pytest tests/
7 changes: 5 additions & 2 deletions src/usepy/list/first.py
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
5 changes: 3 additions & 2 deletions src/usepy/list/last.py
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
6 changes: 4 additions & 2 deletions src/usepy/list/sample.py
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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])
Expand Down
7 changes: 7 additions & 0 deletions src/usepy/typing_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys


if sys.version_info >= (3, 10):
from typing import Union
else:
from typing_extensions import Union
Loading