Skip to content

Minor edits to the descriptor guide #123928

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
Sep 13, 2024
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
10 changes: 6 additions & 4 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ Here are three practical data validation utilities:

def validate(self, value):
if value not in self.options:
raise ValueError(f'Expected {value!r} to be one of {self.options!r}')
raise ValueError(
f'Expected {value!r} to be one of {self.options!r}'
)

class Number(Validator):

Expand Down Expand Up @@ -469,6 +471,7 @@ The descriptors prevent invalid instances from being created:
Traceback (most recent call last):
...
ValueError: Expected -5 to be at least 0

>>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number
Traceback (most recent call last):
...
Expand Down Expand Up @@ -1004,7 +1007,6 @@ here is a pure Python equivalent that implements most of the core functionality:
if doc is None and fget is not None:
doc = fget.__doc__
self.__doc__ = doc
self.__name__ = ''

def __set_name__(self, owner, name):
self.__name__ = name
Expand Down Expand Up @@ -1303,8 +1305,8 @@ mean, median, and other descriptive statistics that depend on the data. However,
there may be useful functions which are conceptually related but do not depend
on the data. For instance, ``erf(x)`` is handy conversion routine that comes up
in statistical work but does not directly depend on a particular dataset.
It can be called either from an object or the class: ``s.erf(1.5) --> .9332`` or
``Sample.erf(1.5) --> .9332``.
It can be called either from an object or the class: ``s.erf(1.5) --> 0.9332``
or ``Sample.erf(1.5) --> 0.9332``.

Since static methods return the underlying function with no changes, the
example calls are unexciting:
Expand Down
Loading