@@ -538,19 +538,18 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
538538.. function :: ismethoddescriptor(object)
539539
540540 Return ``True `` if the object is a method descriptor, but not if
541- :func: `ismethod `, :func: `isclass `, :func: `isfunction ` or :func: `isbuiltin `
542- are true.
541+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` is true.
543542
544543 This, for example, is true of ``int.__add__ ``. An object passing this test
545544 has a :meth: `~object.__get__ ` method, but not a :meth: `~object.__set__ `
546545 method or a :meth: `~object.__delete__ ` method. Beyond that, the set of
547546 attributes varies. A :attr: `~definition.__name__ ` attribute is usually
548547 sensible, and :attr: `~definition.__doc__ ` often is.
549548
550- Methods implemented via descriptors that also pass one of the other tests
551- return `` False `` from the :func: `ismethoddescriptor ` test, simply because the
552- other tests promise more -- you can, e.g. , count on having the
553- :attr: `~method.__func__ ` attribute (etc) when an object passes
549+ Method descriptors that also pass any of the other tests ( :func: ` !isclass `,
550+ :func: ` !ismethod ` or :func: `!isfunction `) make this function return `` False ``,
551+ simply because those other tests promise more -- you can, for example , count
552+ on having the :attr: `~method.__func__ ` attribute when an object passes
554553 :func: `ismethod `.
555554
556555 .. versionchanged :: 3.13
@@ -561,16 +560,28 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
561560
562561.. function :: isdatadescriptor(object)
563562
564- Return ``True `` if the object is a data descriptor.
563+ Return ``True `` if the object is a data descriptor, but not if
564+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` is true.
565565
566- Data descriptors have a :attr: `~object.__set__ ` or a :attr: `~object.__delete__ ` method.
567- Examples are properties (defined in Python), getsets, and members. The
568- latter two are defined in C and there are more specific tests available for
569- those types, which is robust across Python implementations. Typically, data
570- descriptors will also have :attr: `~definition.__name__ ` and :attr: `!__doc__ ` attributes
571- (properties, getsets, and members have both of these attributes), but this is
572- not guaranteed.
566+ Data descriptors always have a :meth: `~object.__set__ ` method and/or
567+ a :meth: `~object.__delete__ ` method. Optionally, they may also have a
568+ :meth: `~object.__get__ ` method.
573569
570+ Examples of data descriptors are :func: `properties <property> `, getsets and
571+ member descriptors. Note that for the latter two (defined only in C extension
572+ modules), more specific tests are available: :func: `isgetsetdescriptor ` and
573+ :func: `ismemberdescriptor `, respectively.
574+
575+ While data descriptors may also have :attr: `~definition.__name__ ` and
576+ :attr: `!__doc__ ` attributes (as properties, getsets and member descriptors
577+ do), this is not necessarily the case in general.
578+
579+ .. versionchanged :: 3.8
580+ This function now reports objects with only a :meth: `~object.__set__ ` method
581+ as being data descriptors (the presence of :meth: `~object.__get__ ` is no
582+ longer required for that). Moreover, objects with :meth: `~object.__delete__ `,
583+ but not :meth: `~object.__set__ `, are now properly recognized as data
584+ descriptors as well, which was not the case previously.
574585
575586.. function :: isgetsetdescriptor(object)
576587
0 commit comments