Python Glossary Русский

all Python 3inspectfunction

inspect.isgetsetdescriptor()

descriptors

Checks that an object is a getset descriptor: an attribute of a C type with a C getter and setter, such as function.__code__.

Syntax

inspect.isgetsetdescriptor(object) -> bool

This is a CPython implementation detail: in other interpreters the function may always return False. A Python property does not qualify; getsets exist only on types written in C. You find one in the __dict__ of a built-in type, not through an instance: f.__code__ already returns the code object. For 'any data descriptor' isdatadescriptor is more reliable.

Examples

import inspect, types
code_attr = types.FunctionType.__dict__['__code__']
print(inspect.isgetsetdescriptor(code_attr))  # → True
print(inspect.isgetsetdescriptor(property(lambda s: 1)))  # → False
print(inspect.isdatadescriptor(code_attr))  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy