@@ -635,19 +635,18 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
635635.. function :: ismethoddescriptor(object)
636636
637637 Return ``True `` if the object is a method descriptor, but not if
638- :func: `ismethod `, :func: `isclass `, :func: `isfunction ` or :func: `isbuiltin `
639- are true.
638+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` is true.
640639
641640 This, for example, is true of ``int.__add__ ``. An object passing this test
642641 has a :meth: `~object.__get__ ` method, but not a :meth: `~object.__set__ `
643642 method or a :meth: `~object.__delete__ ` method. Beyond that, the set of
644643 attributes varies. A :attr: `~definition.__name__ ` attribute is usually
645644 sensible, and :attr: `~definition.__doc__ ` often is.
646645
647- Methods implemented via descriptors that also pass one of the other tests
648- return `` False `` from the :func: `ismethoddescriptor ` test, simply because the
649- other tests promise more -- you can, e.g. , count on having the
650- :attr: `~method.__func__ ` attribute (etc) when an object passes
646+ Method descriptors that also pass any of the other tests ( :func: ` !isclass `,
647+ :func: ` !ismethod ` or :func: `!isfunction `) make this function return `` False ``,
648+ simply because those other tests promise more -- you can, for example , count
649+ on having the :attr: `~method.__func__ ` attribute when an object passes
651650 :func: `ismethod `.
652651
653652 .. versionchanged :: 3.13
@@ -658,16 +657,28 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
658657
659658.. function :: isdatadescriptor(object)
660659
661- Return ``True `` if the object is a data descriptor.
660+ Return ``True `` if the object is a data descriptor, but not if
661+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` is true.
662662
663- Data descriptors have a :attr: `~object.__set__ ` or a :attr: `~object.__delete__ ` method.
664- Examples are properties (defined in Python), getsets, and members. The
665- latter two are defined in C and there are more specific tests available for
666- those types, which is robust across Python implementations. Typically, data
667- descriptors will also have :attr: `~definition.__name__ ` and :attr: `!__doc__ ` attributes
668- (properties, getsets, and members have both of these attributes), but this is
669- not guaranteed.
663+ Data descriptors always have a :meth: `~object.__set__ ` method and/or
664+ a :meth: `~object.__delete__ ` method. Optionally, they may also have a
665+ :meth: `~object.__get__ ` method.
670666
667+ Examples of data descriptors are :func: `properties <property> `, getsets and
668+ member descriptors. Note that for the latter two (defined only in C extension
669+ modules), more specific tests are available: :func: `isgetsetdescriptor ` and
670+ :func: `ismemberdescriptor `, respectively.
671+
672+ While data descriptors may also have :attr: `~definition.__name__ ` and
673+ :attr: `!__doc__ ` attributes (as properties, getsets and member descriptors
674+ do), this is not necessarily the case in general.
675+
676+ .. versionchanged :: 3.8
677+ This function now reports objects with only a :meth: `~object.__set__ ` method
678+ as being data descriptors (the presence of :meth: `~object.__get__ ` is no
679+ longer required for that). Moreover, objects with :meth: `~object.__delete__ `,
680+ but not :meth: `~object.__set__ `, are now properly recognized as data
681+ descriptors as well, which was not the case previously.
671682
672683.. function :: isgetsetdescriptor(object)
673684
0 commit comments