8000 Add more tests to the descriptor howto guide by rhettinger · Pull Request #23506 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Add more tests to the descriptor howto guide #23506

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 4 commits into from
Nov 25, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Doctest the validator application section. The type of Dict.fromkeys(…
…) result.
  • Loading branch information
rhettinger committed Nov 25, 2020
commit 7e9737175cb49aef28570e67ccc69bb2ed86003f
9 changes: 7 additions & 2 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,9 @@ Here's how the data validators can be used in a real class:
self.kind = kind
self.quantity = quantity

The descriptors prevent invalid instances from being created::
The descriptors prevent invalid instances from being created:

.. doctest::

>>> Component('Widget', 'metal', 5) # Blocked: 'Widget' is not all uppercase
Traceback (most recent call last):
Expand Down Expand Up @@ -1243,7 +1245,10 @@ Now a new dictionary of unique keys can be constructed like this:

.. doctest::

>>> Dict.fromkeys('abracadabra')
>>> d = Dict.fromkeys('abracadabra')
>>> type(d) is Dict
True
>>> d
{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}

Using the non-data descriptor protocol, a pure Python version of
Expand Down
0