Python Glossary Русский

all Python 3inspectfunction

inspect.ismemberdescriptor()

descriptors

Checks that an object is a member descriptor: a field stored at a fixed place in the object, like __slots__ entries or fields of C structs.

Syntax

inspect.ismemberdescriptor(object) -> bool

The most common source is your own __slots__: each slot name turns into a member descriptor in the class __dict__. Through an instance you get the value, and for an unset slot AttributeError, even though the name exists on the class. A property does not qualify. Like isgetsetdescriptor, this is a CPython implementation detail.

Examples

import inspect
class Point:
    __slots__ = ('x', 'y')
print(inspect.ismemberdescriptor(Point.__dict__['x']))  # → True
p = Point()
p.x = 1
try:
    p.y
except AttributeError:
    print('слот y пуст')  # → слот y пуст

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy