Skip to content

Commit

Permalink
Add CI for Python 3.10 (#38)
Browse files Browse the repository at this point in the history
* Add CI for Python 3.10

* Exclude 3.6 on mac

* Unpin pytest version

* pypy doesn't work on macOS image

* Improve detection of just-started generator

* We can start the generator outside the func

* Branch coverage
  • Loading branch information
cjrh committed Oct 23, 2021
1 parent f4ee8b7 commit 582cf91
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ jobs:
timeout-minutes: 5
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', 'pypy3']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy3']
os: [ubuntu-latest, windows-latest, macOS-latest]
exclude:
- os: macOS-latest
python-version: '3.6'
- os: macOS-latest
python-version: 'pypy3'
fail-fast: false
steps:
- uses: actions/checkout@v1
Expand Down
49 changes: 28 additions & 21 deletions excitertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3814,15 +3814,11 @@ def send(self, collector: Generator, close_collector_when_done=False) -> "None":
Note that Iter.send_ is a sink, so no further chaining is allowed.
"""
if inspect.getgeneratorstate(collector) == 'GEN_CREATED':
next(collector)

for v in self:
try:
collector.send(v)
except TypeError as e:
if "just-started generator" in str(e):
next(collector)
collector.send(v)
else: # pragma: no cover
raise
collector.send(v)

if close_collector_when_done:
collector.close()
Expand All @@ -3831,11 +3827,10 @@ def send_also(self, collector: Generator) -> "Iter":
"""
Reference: `more_itertools.consumer <https://more-itertools.readthedocs.io/en/stable/api.html?highlight=numeric_range#more_itertools.consumer>`_
Some ideas around a reverse iterator as a sink. The requirement to
first "next" a just-started generator before you can send values
into it is irritating, but not insurmountable. This method will
automatically detect the "just-started generator" situation, do the
``next()``, and then send in the first value as necessary.
Some ideas around a reverse iterator as a sink. Usually you have
first to "send" a ``None`` into a generator if you want to send
more values into it (or call ``next()`` on it), but we handle
that automatically.
Simple case:
Expand All @@ -3850,6 +3845,22 @@ def send_also(self, collector: Generator) -> "Iter":
>>> output
[0, 1, 2]
However, if the caller already started the generator, that
works too:
.. code-block:: python
>>> output = []
>>> def collector():
... while True:
... output.append((yield))
>>> g = collector()
>>> next(g) # This "starts" the generator
>>> Iter.range(3).send_also(g).collect()
[0, 1, 2]
>>> output
[0, 1, 2]
If the generator is closed before the iteration is complete,
you'll get an exception (Python 3.7+):
Expand All @@ -3874,15 +3885,11 @@ def send_also(self, collector: Generator) -> "Iter":
live at least as long as the iterator feeding it.
"""
if inspect.getgeneratorstate(collector) == 'GEN_CREATED':
next(collector)

def func(v):
try:
collector.send(v)
except TypeError as e:
if "just-started generator" in str(e):
next(collector)
collector.send(v)
else: # pragma: no cover
raise
collector.send(v)

return self.side_effect(func)

Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest==6.2.3
pytest
pytest-cov
coveralls
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down

0 comments on commit 582cf91

Please sign in to comment.