[3.13] Minor edits to the descriptor guide (GH-123928) (#124079)

Minor edits to the descriptor guide (GH-123928)
(cherry picked from commit cd06f5e323)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-09-23 20:07:56 +02:00 committed by GitHub
parent 4cd4bf10be
commit b2ffd492cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -389,7 +389,9 @@ Here are three practical data validation utilities:
def validate(self, value): def validate(self, value):
if value not in self.options: 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): class Number(Validator):
@ -469,6 +471,7 @@ The descriptors prevent invalid instances from being created:
Traceback (most recent call last): Traceback (most recent call last):
... ...
ValueError: Expected -5 to be at least 0 ValueError: Expected -5 to be at least 0
>>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number >>> Component('WIDGET', 'metal', 'V') # Blocked: 'V' isn't a number
Traceback (most recent call last): Traceback (most recent call last):
... ...
@ -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: if doc is None and fget is not None:
doc = fget.__doc__ doc = fget.__doc__
self.__doc__ = doc self.__doc__ = doc
self.__name__ = ''
def __set_name__(self, owner, name): def __set_name__(self, owner, name):
self.__name__ = name self.__name__ = name
@ -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 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 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. 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 It can be called either from an object or the class: ``s.erf(1.5) --> 0.9332``
``Sample.erf(1.5) --> .9332``. or ``Sample.erf(1.5) --> 0.9332``.
Since static methods return the underlying function with no changes, the Since static methods return the underlying function with no changes, the
example calls are unexciting: example calls are unexciting: