Python Glossary Русский

all Python 3deprecated in 3.3abcterm

abc.abstractproperty

abstract classes

Deprecated: an abstract property. Use @property on top of @abstractmethod instead.

Syntax

@abc.abstractproperty  # deprecated

Same story as abstractclassmethod: since Python 3.3 property itself reports the abstractness of the function it wraps, which made the dedicated decorator redundant. In the modern replacement the order matters — @property on the outside, @abstractmethod directly above the function, never the other way round.

Examples

import abc
print(callable(abc.abstractproperty))   # → True
print(issubclass(abc.abstractproperty, property))   # → True
import abc
class Shape(abc.ABC): area = abc.abstractproperty(lambda self: 0)
print(Shape.__abstractmethods__)   # → frozenset({'area'})
print(Shape())   # → TypeError (класс абстрактный)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy