Skip to content

💡 Add overload for of method to support generator streams #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged
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/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox and any other packages
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v1.16
uses: JRubics/poetry-publish@v2.1
with:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}
10 changes: 5 additions & 5 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# If you wanted to use multiple Python versions, you'd have specify a matrix in the job and
# reference the matrixe python version here.
- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: 3.9

Expand All @@ -31,7 +31,7 @@ jobs:
# manually if/when you want to upgrade Poetry, or if something goes wrong. This could be
# mildly cleaner by using an environment variable, but I don't really care.
- name: cache poetry install
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.local
key: poetry-1.4.2-0
Expand All @@ -47,7 +47,7 @@ jobs:
# cache it.
- uses: snok/install-poetry@v1
with:
version: 1.4.2
version: 2.1.0
virtualenvs-create: true
virtualenvs-in-project: true

Expand All @@ -56,7 +56,7 @@ jobs:
# them in the cache key. I'm not, so it can be simple and just depend on the poetry.lock.
- name: cache deps
id: cache-deps
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: .venv
key: pydeps-${{ hashFiles('**/poetry.lock') }}
Expand Down
900 changes: 772 additions & 128 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ packages = [
]

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
joblib = ">=1.2,<=1.4.2"
python = ">=3.10,<4.0"
joblib = ">=1.2.0"
defusedxml = { version = ">=0.7,<0.8", optional = true }
pyyaml = "^6.0.1"
tomlkit = "^0.13.2"
Expand All @@ -33,6 +33,10 @@ coverage = "*"
[tool.poetry.group.lint.dependencies]
pylint = "*"

[tool.poetry.group.benchmark.dependencies]
rich = "^14.0.0"
matplotlib = "^3.10.3"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
13 changes: 12 additions & 1 deletion pystreamapi/__stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import itertools
from typing import Iterable, TypeVar, Callable, Optional, overload, Union, Sized, Generator
from collections.abc import Sized
from typing import Iterable, TypeVar, Callable, Optional, overload, Union, Generator

from pystreamapi.__iterate import iterate
from pystreamapi._streams.__base_stream import BaseStream
Expand Down Expand Up @@ -34,6 +35,16 @@ def of(source: Iterable[_K]) -> BaseStream[_K]:
:param source:
"""

@staticmethod
@overload
def of(source: Generator[_K, None, None]) -> NumericBaseStream:
"""
Create a new Stream from a generator. The implementation will use a sequential stream.
If you need a parallel or numeric stream, use the appropriate method.

:param source:
"""

@staticmethod
def of(source: Union[Iterable, Generator, Sized]):
"""
Expand Down
Loading