-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Support Receives section for generator.send(...) params #145
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
{{parameters}} | ||
{{returns}} | ||
{{yields}} | ||
{{sent}} | ||
{{other_parameters}} | ||
{{raises}} | ||
{{warns}} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,25 @@ | |
doc_yields = NumpyDocString(doc_yields_txt) | ||
|
||
|
||
doc_sent_txt = """ | ||
Test generator | ||
|
||
Yields | ||
------ | ||
a : int | ||
The number of apples. | ||
|
||
Sent | ||
---- | ||
b : int | ||
The number of bananas. | ||
c : int | ||
The number of oranges. | ||
|
||
""" | ||
doc_sent = NumpyDocString(doc_sent_txt) | ||
|
||
|
||
def test_signature(): | ||
assert doc['Signature'].startswith('numpy.multivariate_normal(') | ||
assert doc['Signature'].endswith('spam=None)') | ||
|
@@ -211,6 +230,38 @@ def test_yields(): | |
assert desc[0].endswith(end) | ||
|
||
|
||
def test_sent(): | ||
section = doc_sent['Sent'] | ||
assert_equal(len(section), 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CI isn't happy: You can just change this to plain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and some more of the same several lines below |
||
truth = [('b', 'int', 'bananas.'), | ||
('c', 'int', 'oranges.')] | ||
for (arg, arg_type, desc), (arg_, arg_type_, end) in zip(section, truth): | ||
assert_equal(arg, arg_) | ||
assert_equal(arg_type, arg_type_) | ||
assert desc[0].startswith('The number of') | ||
assert desc[0].endswith(end) | ||
|
||
|
||
def test_returnyield(): | ||
doc_text = """ | ||
Test having returns and yields. | ||
|
||
Returns | ||
------- | ||
int | ||
The number of apples. | ||
|
||
Yields | ||
------ | ||
a : int | ||
The number of apples. | ||
b : int | ||
The number of bananas. | ||
|
||
""" | ||
assert_raises(ValueError, NumpyDocString, doc_text) | ||
|
||
|
||
def test_returnyield(): | ||
doc_text = """ | ||
Test having returns and yields. | ||
|
@@ -462,6 +513,25 @@ def test_yield_str(): | |
.. index:: """) | ||
|
||
|
||
def test_sent_str(): | ||
line_by_line_compare(str(doc_sent), | ||
"""Test generator | ||
|
||
Yields | ||
------ | ||
a : int | ||
The number of apples. | ||
|
||
Sent | ||
---- | ||
b : int | ||
The number of bananas. | ||
c : int | ||
The number of oranges. | ||
|
||
.. index:: """) | ||
|
||
|
||
def test_sphinx_str(): | ||
sphinx_doc = SphinxDocString(doc_txt) | ||
line_by_line_compare(str(sphinx_doc), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit torn about the order of Yields and Sent. Putting Sent first feels more natural to the way you use
send
(in that the next value to come out probably depends on the value you sent in or you would not be bothering to send anything in!).On the other hand it yields a non-trivial value before you can send in a non trivial value so it should stay in this order.
On the other other hand, you do send in
None
first to prime the generator (but that is not what is being documented in this block).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had thought the idiom was to use
next
initially, then.send
later.I think the discomfort is partially with the sense of the word "Sent", which connotes a departing aspect (perhaps because it is not agentive). "Receives", in contrast, seems to fit better after "Yields".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I had not seen that idiom. I like sending
None
as it special-cases the first round less, but that is neither here nor there for this discussion."The generator is sent ..." vs "The generator receives ..."
The first is odd because we drop the 'is' in the section title and the second is odd because it feel more passive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"receives" sounds more correct than "sent" in my head.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer "receives" as well. Another possibility I can think of is "accepts," but I don't think I like that as much as "receives".