Skip to content

Commit c1b3e6c

Browse files
committed
Deploying to gh-pages from @ 29fd773 🚀
1 parent 1514f5a commit c1b3e6c

File tree

540 files changed

+4596
-4519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

540 files changed

+4596
-4519
lines changed

.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: a722cb470f646be1f9759369084d7fc6
3+
config: b5e4c3d3c642f1dad50dbe268201b58a
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

_sources/library/dataclasses.rst.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,9 @@ methods will raise a :exc:`FrozenInstanceError` when invoked.
613613

614614
There is a tiny performance penalty when using ``frozen=True``:
615615
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
616-
must use :meth:`!__setattr__`.
616+
must use :meth:`!object.__setattr__`.
617+
618+
.. Make sure to not remove "object" from "object.__setattr__" in the above markup!
617619
618620
.. _dataclasses-inheritance:
619621

_sources/library/functions.rst.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,13 @@ are always available. They are listed here in alphabetical order.
604604
will be used for both the global and the local variables. If *globals* and
605605
*locals* are given, they are used for the global and local variables,
606606
respectively. If provided, *locals* can be any mapping object. Remember
607-
that at the module level, globals and locals are the same dictionary. If exec
608-
gets two separate objects as *globals* and *locals*, the code will be
609-
executed as if it were embedded in a class definition.
607+
that at the module level, globals and locals are the same dictionary.
608+
609+
.. note::
610+
611+
Most users should just pass a *globals* argument and never *locals*.
612+
If exec gets two separate objects as *globals* and *locals*, the code
613+
will be executed as if it were embedded in a class definition.
610614

611615
If the *globals* dictionary does not contain a value for the key
612616
``__builtins__``, a reference to the dictionary of the built-in module

_sources/library/hashlib.rst.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
328328
your application, read *Appendix A.2.2* of NIST-SP-800-132_. The answers
329329
on the `stackexchange pbkdf2 iterations question`_ explain in detail.
330330

331-
*dklen* is the length of the derived key. If *dklen* is ``None`` then the
331+
*dklen* is the length of the derived key in bytes. If *dklen* is ``None`` then the
332332
digest size of the hash algorithm *hash_name* is used, e.g. 64 for SHA-512.
333333

334334
>>> from hashlib import pbkdf2_hmac
@@ -357,7 +357,7 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
357357

358358
*n* is the CPU/Memory cost factor, *r* the block size, *p* parallelization
359359
factor and *maxmem* limits memory (OpenSSL 1.1.0 defaults to 32 MiB).
360-
*dklen* is the length of the derived key.
360+
*dklen* is the length of the derived key in bytes.
361361

362362
.. versionadded:: 3.6
363363

_sources/library/itertools.rst.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -690,18 +690,19 @@ loops that truncate the stream.
690690

691691
def tee(iterable, n=2):
692692
iterator = iter(iterable)
693-
empty_link = [None, None] # Singly linked list: [value, link]
694-
return tuple(_tee(iterator, empty_link) for _ in range(n))
693+
shared_link = [None, None]
694+
return tuple(_tee(iterator, shared_link) for _ in range(n))
695695

696696
def _tee(iterator, link):
697-
while True:
698-
if link[1] is None:
699-
try:
700-
link[:] = [next(iterator), [None, None]]
701-
except StopIteration:
702-
return
703-
value, link = link
704-
yield value
697+
try:
698+
while True:
699+
if link[1] is None:
700+
link[0] = next(iterator)
701+
link[1] = [None, None]
702+
value, link = link
703+
yield value
704+
except StopIteration:
705+
return
705706

706707
Once a :func:`tee` has been created, the original *iterable* should not be
707708
used anywhere else; otherwise, the *iterable* could get advanced without

_sources/library/marshal.rst.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
This module contains functions that can read and write Python values in a binary
1111
format. The format is specific to Python, but independent of machine
1212
architecture issues (e.g., you can write a Python value to a file on a PC,
13-
transport the file to a Sun, and read it back there). Details of the format are
13+
transport the file to a Mac, and read it back there). Details of the format are
1414
undocumented on purpose; it may change between Python versions (although it
1515
rarely does). [#]_
1616

_sources/library/socket.rst.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,8 @@ to sockets.
15841584
Return a :term:`file object` associated with the socket. The exact returned
15851585
type depends on the arguments given to :meth:`makefile`. These arguments are
15861586
interpreted the same way as by the built-in :func:`open` function, except
1587-
the only supported *mode* values are ``'r'`` (default), ``'w'`` and ``'b'``.
1587+
the only supported *mode* values are ``'r'`` (default), ``'w'``, ``'b'``, or
1588+
a combination of those.
15881589

15891590
The socket must be in blocking mode; it can have a timeout, but the file
15901591
object's internal buffer may end up in an inconsistent state if a timeout

_sources/library/stdtypes.rst.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,7 +4556,7 @@ can be used interchangeably to index the same dictionary entry.
45564556

45574557
Return a shallow copy of the dictionary.
45584558

4559-
.. classmethod:: fromkeys(iterable[, value])
4559+
.. classmethod:: fromkeys(iterable, value=None)
45604560

45614561
Create a new dictionary with keys from *iterable* and values set to *value*.
45624562

@@ -4566,7 +4566,7 @@ can be used interchangeably to index the same dictionary entry.
45664566
such as an empty list. To get distinct values, use a :ref:`dict
45674567
comprehension <dict>` instead.
45684568

4569-
.. method:: get(key[, default])
4569+
.. method:: get(key, default=None)
45704570

45714571
Return the value for *key* if *key* is in the dictionary, else *default*.
45724572
If *default* is not given, it defaults to ``None``, so that this method
@@ -4608,7 +4608,7 @@ can be used interchangeably to index the same dictionary entry.
46084608

46094609
.. versionadded:: 3.8
46104610

4611-
.. method:: setdefault(key[, default])
4611+
.. method:: setdefault(key, default=None)
46124612

46134613
If *key* is in the dictionary, return its value. If not, insert *key*
46144614
with a value of *default* and return *default*. *default* defaults to

_sources/library/threading.rst.txt

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,25 @@ and "recursion level" in addition to the locked/unlocked state used by primitive
594594
locks. In the locked state, some thread owns the lock; in the unlocked state,
595595
no thread owns it.
596596

597-
To lock the lock, a thread calls its :meth:`~RLock.acquire` method; this
598-
returns once the thread owns the lock. To unlock the lock, a thread calls
599-
its :meth:`~Lock.release` method. :meth:`~Lock.acquire`/:meth:`~Lock.release`
600-
call pairs may be nested; only the final :meth:`~Lock.release` (the
601-
:meth:`~Lock.release` of the outermost pair) resets the lock to unlocked and
602-
allows another thread blocked in :meth:`~Lock.acquire` to proceed.
597+
Threads call a lock's :meth:`~RLock.acquire` method to lock it,
598+
and its :meth:`~Lock.release` method to unlock it.
603599

604-
Reentrant locks also support the :ref:`context management protocol <with-locks>`.
600+
.. note::
601+
602+
Reentrant locks support the :ref:`context management protocol <with-locks>`,
603+
so it is recommended to use :keyword:`with` instead of manually calling
604+
:meth:`~RLock.acquire` and :meth:`~RLock.release`
605+
to handle acquiring and releasing the lock for a block of code.
606+
607+
RLock's :meth:`~RLock.acquire`/:meth:`~RLock.release` call pairs may be nested,
608+
unlike Lock's :meth:`~Lock.acquire`/:meth:`~Lock.release`. Only the final
609+
:meth:`~RLock.release` (the :meth:`~Lock.release` of the outermost pair) resets
610+
the lock to an unlocked state and allows another thread blocked in
611+
:meth:`~RLock.acquire` to proceed.
612+
613+
:meth:`~RLock.acquire`/:meth:`~RLock.release` must be used in pairs: each acquire
614+
must have a release in the thread that has acquired the lock. Failing to
615+
call release as many times the lock has been acquired can lead to deadlock.
605616

606617

607618
.. class:: RLock()
@@ -620,25 +631,41 @@ Reentrant locks also support the :ref:`context management protocol <with-locks>`
620631

621632
Acquire a lock, blocking or non-blocking.
622633

623-
When invoked without arguments: if this thread already owns the lock, increment
624-
the recursion level by one, and return immediately. Otherwise, if another
625-
thread owns the lock, block until the lock is unlocked. Once the lock is
626-
unlocked (not owned by any thread), then grab ownership, set the recursion level
627-
to one, and return. If more than one thread is blocked waiting until the lock
628-
is unlocked, only one at a time will be able to grab ownership of the lock.
629-
There is no return value in this case.
634+
.. seealso::
630635

631-
When invoked with the *blocking* argument set to ``True``, do the same thing as when
632-
called without arguments, and return ``True``.
636+
:ref:`Using RLock as a context manager <with-locks>`
637+
Recommended over manual :meth:`!acquire` and :meth:`release` calls
638+
whenever practical.
633639

634-
When invoked with the *blocking* argument set to ``False``, do not block. If a call
635-
without an argument would block, return ``False`` immediately; otherwise, do the
636-
same thing as when called without arguments, and return ``True``.
637640

638-
When invoked with the floating-point *timeout* argument set to a positive
639-
value, block for at most the number of seconds specified by *timeout*
640-
and as long as the lock cannot be acquired. Return ``True`` if the lock has
641-
been acquired, ``False`` if the timeout has elapsed.
641+
When invoked with the *blocking* argument set to ``True`` (the default):
642+
643+
* If no thread owns the lock, acquire the lock and return immediately.
644+
645+
* If another thread owns the lock, block until we are able to acquire
646+
lock, or *timeout*, if set to a positive float value.
647+
648+
* If the same thread owns the lock, acquire the lock again, and
649+
return immediately. This is the difference between :class:`Lock` and
650+
:class:`!RLock`; :class:`Lock` handles this case the same as the previous,
651+
blocking until the lock can be acquired.
652+
653+
When invoked with the *blocking* argument set to ``False``:
654+
655+
* If no thread owns the lock, acquire the lock and return immediately.
656+
657+
* If another thread owns the lock, return immediately.
658+
659+
* If the same thread owns the lock, acquire the lock again and return
660+
immediately.
661+
662+
In all cases, if the thread was able to acquire the lock, return ``True``.
663+
If the thread was unable to acquire the lock (i.e. if not blocking or
664+
the timeout was reached) return ``False``.
665+
666+
If called multiple times, failing to call :meth:`~RLock.release` as many times
667+
may lead to deadlock. Consider using :class:`!RLock` as a context manager rather than
668+
calling acquire/release directly.
642669

643670
.. versionchanged:: 3.2
644671
The *timeout* parameter is new.
@@ -654,7 +681,7 @@ Reentrant locks also support the :ref:`context management protocol <with-locks>`
654681

655682
Only call this method when the calling thread owns the lock. A
656683
:exc:`RuntimeError` is raised if this method is called when the lock is
657-
unlocked.
684+
not acquired.
658685

659686
There is no return value.
660687

_sources/library/unittest.mock.rst.txt

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,13 @@ the *new_callable* argument to :func:`patch`.
410410

411411
This can be useful where you want to make a series of assertions that
412412
reuse the same object. Note that :meth:`reset_mock` *doesn't* clear the
413-
return value, :attr:`side_effect` or any child attributes you have
413+
:attr:`return_value`, :attr:`side_effect` or any child attributes you have
414414
set using normal assignment by default. In case you want to reset
415-
*return_value* or :attr:`side_effect`, then pass the corresponding
415+
:attr:`return_value` or :attr:`side_effect`, then pass the corresponding
416416
parameter as ``True``. Child mocks and the return value mock
417417
(if any) are reset as well.
418418

419-
.. note:: *return_value*, and :attr:`side_effect` are keyword-only
419+
.. note:: *return_value*, and *side_effect* are keyword-only
420420
arguments.
421421

422422

@@ -2535,40 +2535,16 @@ called incorrectly.
25352535

25362536
Before I explain how auto-speccing works, here's why it is needed.
25372537

2538-
:class:`Mock` is a very powerful and flexible object, but it suffers from two flaws
2539-
when used to mock out objects from a system under test. One of these flaws is
2540-
specific to the :class:`Mock` api and the other is a more general problem with using
2541-
mock objects.
2538+
:class:`Mock` is a very powerful and flexible object, but it suffers from a flaw which
2539+
is general to mocking. If you refactor some of your code, rename members and so on, any
2540+
tests for code that is still using the *old api* but uses mocks instead of the real
2541+
objects will still pass. This means your tests can all pass even though your code is
2542+
broken.
25422543

2543-
First the problem specific to :class:`Mock`. :class:`Mock` has two assert methods that are
2544-
extremely handy: :meth:`~Mock.assert_called_with` and
2545-
:meth:`~Mock.assert_called_once_with`.
2544+
.. versionchanged:: 3.5
25462545

2547-
>>> mock = Mock(name='Thing', return_value=None)
2548-
>>> mock(1, 2, 3)
2549-
>>> mock.assert_called_once_with(1, 2, 3)
2550-
>>> mock(1, 2, 3)
2551-
>>> mock.assert_called_once_with(1, 2, 3)
2552-
Traceback (most recent call last):
2553-
...
2554-
AssertionError: Expected 'mock' to be called once. Called 2 times.
2555-
2556-
Because mocks auto-create attributes on demand, and allow you to call them
2557-
with arbitrary arguments, if you misspell one of these assert methods then
2558-
your assertion is gone:
2559-
2560-
.. code-block:: pycon
2561-
2562-
>>> mock = Mock(name='Thing', return_value=None)
2563-
>>> mock(1, 2, 3)
2564-
>>> mock.assret_called_once_with(4, 5, 6) # Intentional typo!
2565-
2566-
Your tests can pass silently and incorrectly because of the typo.
2567-
2568-
The second issue is more general to mocking. If you refactor some of your
2569-
code, rename members and so on, any tests for code that is still using the
2570-
*old api* but uses mocks instead of the real objects will still pass. This
2571-
means your tests can all pass even though your code is broken.
2546+
Before 3.5, tests with a typo in the word assert would silently pass when they should
2547+
raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock.
25722548

25732549
Note that this is another reason why you need integration tests as well as
25742550
unit tests. Testing everything in isolation is all fine and dandy, but if you

0 commit comments

Comments
 (0)