@@ -513,20 +513,19 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
513
513
.. function :: ismethoddescriptor(object)
514
514
515
515
Return ``True `` if the object is a method descriptor, but not if
516
- :func: `ismethod `, :func: `isclass `, :func: `isfunction ` or :func: `isbuiltin `
517
- are true.
516
+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` are true.
518
517
519
518
This, for example, is true of ``int.__add__ ``. An object passing this test
520
519
has a :meth: `~object.__get__ ` method, but not a :meth: `~object.__set__ `
521
520
method or a :meth: `~object.__delete__ ` method. Beyond that, the set of
522
521
attributes varies. A :attr: `~definition.__name__ ` attribute is usually
523
522
sensible, and :attr: `!__doc__ ` often is.
524
523
525
- Methods implemented via descriptors that also pass one of the other tests
526
- return `` False `` from the :func: `ismethoddescriptor ` test, simply because the
527
- other tests promise more -- you can, e.g., count on having the
528
- :attr: `~method.__func__ ` attribute (etc) when an object passes
529
- :func: `ismethod `.
524
+ Objects implemented as descriptors that also pass one of the other tests
525
+ ( :func: ` isclass `, :func: ` ismethod ` or :func: `isfunction `) make this function
526
+ return `` False ``, simply because the other tests promise more -- you can,
527
+ e.g., count on having the :attr: `~method.__func__ ` attribute (etc. ) when an
528
+ object passes :func: `ismethod `.
530
529
531
530
.. versionchanged :: 3.13
532
531
This function no longer incorrectly reports objects with :meth: `~object.__get__ `
@@ -536,35 +535,48 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
536
535
537
536
.. function :: isdatadescriptor(object)
538
537
539
- Return ``True `` if the object is a data descriptor.
538
+ Return ``True `` if the object is a data descriptor, but not if
539
+ :func: `isclass `, :func: `ismethod ` or :func: `isfunction ` are true.
540
540
541
- Data descriptors have a :attr: `~object.__set__ ` or a :attr: `~object.__delete__ ` method.
542
- Examples are properties (defined in Python), getsets, and members. The
543
- latter two are defined in C and there are more specific tests available for
544
- those types, which is robust across Python implementations. Typically, data
545
- descriptors will also have :attr: `~definition.__name__ ` and :attr: `!__doc__ ` attributes
546
- (properties, getsets, and members have both of these attributes), but this is
547
- not guaranteed.
541
+ Data descriptors always have a :meth: `~object.__set__ ` method and/or
542
+ a :meth: `~object.__delete__ ` method. Optionally, they may also have a
543
+ :meth: `~object.__get__ ` method.
544
+
545
+ Examples of data descriptors include *properties * (see: :func: `property `),
546
+ *getset descriptors * and *member descriptors * (for the latter two, more
547
+ specific tests are available as well: :func: `isgetsetdescriptor ` and
548
+ :func: `ismemberdescriptor `, respectively).
549
+
550
+ Typically, data descriptors have also :attr: `~definition.__name__ ` and
551
+ :attr: `!__doc__ ` attributes (*properties *, *getsets *, and *members * have
552
+ both of them), but this is not guaranteed.
553
+
554
+ .. versionchanged :: 3.8
555
+ Now this function reports objects with only a :meth: `~object.__set__ ` method
556
+ as being data descriptors (the presence of :meth: `~object.__get__ ` is no
557
+ longer required for that). Moreover, objects with :meth: `~object.__delete__ `,
558
+ but not :meth: `~object.__set__ `, are now properly recognized as data
559
+ descriptors as well (formerly, they were not).
548
560
549
561
550
562
.. function :: isgetsetdescriptor(object)
551
563
552
- Return ``True `` if the object is a getset descriptor.
564
+ Return ``True `` if the object is a * getset descriptor * .
553
565
554
566
.. impl-detail ::
555
567
556
- getsets are attributes defined in extension modules via
568
+ * getsets * are attributes defined in extension modules via
557
569
:c:type: `PyGetSetDef ` structures. For Python implementations without such
558
570
types, this method will always return ``False ``.
559
571
560
572
561
573
.. function :: ismemberdescriptor(object)
562
574
563
- Return ``True `` if the object is a member descriptor.
575
+ Return ``True `` if the object is a * member descriptor * .
564
576
565
577
.. impl-detail ::
566
578
567
- Member descriptors are attributes defined in extension modules via
579
+ * Member descriptors * are attributes defined in extension modules via
568
580
:c:type: `PyMemberDef ` structures. For Python implementations without such
569
581
types, this method will always return ``False ``.
570
582
@@ -1511,11 +1523,11 @@ but avoids executing code when it fetches attributes.
1511
1523
.. versionadded :: 3.2
1512
1524
1513
1525
:func: `getattr_static ` does not resolve descriptors, for example slot descriptors or
1514
- getset descriptors on objects implemented in C. The descriptor object
1526
+ * getset * descriptors on objects implemented in C. The descriptor object
1515
1527
is returned instead of the underlying attribute.
1516
1528
1517
1529
You can handle these with code like the following. Note that
1518
- for arbitrary getset descriptors invoking these may trigger
1530
+ for arbitrary * getset * descriptors invoking these may trigger
1519
1531
code execution::
1520
1532
1521
1533
# example code for resolving the builtin descriptor types
0 commit comments