Skip to content

Minor changes in Doc/faq/library. #15449

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 5 commits into from
Sep 9, 2019
Merged
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
29 changes: 15 additions & 14 deletions Doc/faq/library.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ argument list. It is called as ::

handler(signum, frame)

so it should be declared with two arguments::
so it should be declared with two parameters::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, a function is called with arguments and declared with parameters.


def handler(signum, frame):
...
Expand Down Expand Up @@ -159,9 +159,9 @@ The "global main logic" of your program may be as simple as ::

at the bottom of the main module of your program.

Once your program is organized as a tractable collection of functions and class
behaviours you should write test functions that exercise the behaviours. A test
suite that automates a sequence of tests can be associated with each module.
Once your program is organized as a tractable collection of function and class
Copy link
Contributor

@aeros aeros Aug 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section is okay as it is. I can see where you were going with this though, you might have assumed that the "and" was implying: "... collection of functions behaviors and class behaviors" (which would be grammatically incorrect). But, in this case the two are entirely separate. The "behaviors" part is only connected to "class". The two items are:

  1. Collection of functions
  2. Collection of class behaviors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I don't understand why the doc states that "you should write test functions that exercise the behaviours". If "behaviours" only applies to "class" and not to "function", then the doc would say that functions not embedded into classes should not be tested. Am I missing something here ?

Copy link
Contributor

@aeros aeros Aug 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "behaviours" only applies to "class" and not to "function", then the doc would say that functions not embedded into classes should not be tested.

Hmm, good point. I might've been looking at this correction too much in isolation without fully considering the surrounding context. While reading over that sentence a couple of times, I also realized it's missing a comma:

Once your program is organized as a tractable collection of function and class
behaviours, you should write test functions that exercise the behaviours.

Also an interesting tidbit (this is definitely subjective though, so I wouldn't suggest changing it for this PR), but we actually alternate between the American English and British English versions of "behaviors/behaviours" within the documentation:

$ git grep -E "behaviors" -- "*.rst" | wc -l
26
$ git grep -E "behaviours" -- "*.rst" | wc -l
8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice catch (never occured to me there were two versions of this word). I've added the comma.

behaviours, you should write test functions that exercise the behaviours. A
test suite that automates a sequence of tests can be associated with each module.
This sounds like a lot of work, but since Python is so terse and flexible it's
surprisingly easy. You can make coding much more pleasant and fun by writing
your test functions in parallel with the "production code", since this makes it
Expand Down Expand Up @@ -295,7 +295,7 @@ queue as there are threads.
How do I parcel out work among a bunch of worker threads?
---------------------------------------------------------

The easiest way is to use the new :mod:`concurrent.futures` module,
The easiest way is to use the :mod:`concurrent.futures` module,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, concurrent.futures is no longer new.

especially the :mod:`~concurrent.futures.ThreadPoolExecutor` class.

Or, if you want fine control over the dispatching algorithm, you can write
Expand Down Expand Up @@ -679,7 +679,7 @@ How can I mimic CGI form submission (METHOD=POST)?
I would like to retrieve web pages that are the result of POSTing a form. Is
there existing code that would let me do this easily?

Yes. Here's a simple example that uses urllib.request::
Yes. Here's a simple example that uses :mod:`urllib.request`::

#!/usr/local/bin/python

Expand Down Expand Up @@ -765,20 +765,21 @@ The :mod:`select` module is commonly used to help with asynchronous I/O on
sockets.

To prevent the TCP connect from blocking, you can set the socket to non-blocking
mode. Then when you do the ``connect()``, you will either connect immediately
mode. Then when you do the :meth:`socket.connect`, you will either connect immediately
(unlikely) or get an exception that contains the error number as ``.errno``.
``errno.EINPROGRESS`` indicates that the connection is in progress, but hasn't
finished yet. Different OSes will return different values, so you're going to
have to check what's returned on your system.

You can use the ``connect_ex()`` method to avoid creating an exception. It will
just return the errno value. To poll, you can call ``connect_ex()`` again later
You can use the :meth:`socket.connect_ex` method to avoid creating an exception. It will
just return the errno value. To poll, you can call :meth:`socket.connect_ex` again later
-- ``0`` or ``errno.EISCONN`` indicate that you're connected -- or you can pass this
socket to select to check if it's writable.
socket to :meth:`select.select` to check if it's writable.

.. note::
The :mod:`asyncore` module presents a framework-like approach to the problem
of writing non-blocking networking code.
The :mod:`asyncio` module provides a general purpose single-threaded and
concurrent asynchronous library, which can be used for writing non-blocking
network code.
The third-party `Twisted <https://twistedmatrix.com/trac/>`_ library is
a popular and feature-rich alternative.

Expand Down Expand Up @@ -832,8 +833,8 @@ There are also many other specialized generators in this module, such as:

Some higher-level functions operate on sequences directly, such as:

* ``choice(S)`` chooses random element from a given sequence
* ``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly
* ``choice(S)`` chooses a random element from a given sequence.
* ``shuffle(L)`` shuffles a list in-place, i.e. permutes it randomly.

There's also a ``Random`` class you can instantiate to create independent
multiple random number generators.