Method and Property Types

Concrete class

File 7 appendix/method.py

class MethodTypeExample:
    """Example class."""

    def method(self, x):
        """Method."""

    def generator(self, x):
        """Generator."""
        yield 1

    @classmethod
    def class_method(cls, x):
        """Class method."""

    @staticmethod
    def static_method(x):
        """Static method."""

    @property
    def read_only_property(x):
        """Read only property."""

    @property
    def read_write_property(x):
        """Read write property."""

    @read_write_property.setter
    def read_write_property(x):
        pass
![mkapi](appendix.method.MethodTypeExample|short)
class
MethodTypeExample()

Example class.

Attributes
  • read_only_property Read only property.
  • read_write_property Read write property.
Methods
method
method(x)

Method.

generator
generator(x)

Generator.

classmethod
class_method(x)

Class method.

staticmethod
static_method(x)

Static method.

Abstract class

File 8 appendix/abc.py

from abc import ABC, abstractmethod


class AbstractMethodTypeExample(ABC):
    """Abstract class."""

    def method(self):
        """Method."""

    @classmethod
    def class_method(cls):
        """Class method."""

    @staticmethod
    def static_method():
        """Static method."""

    @abstractmethod
    def abstract_method(self):
        """Abstract method."""

    @classmethod
    @abstractmethod
    def abstract_class_method(cls):
        """Abstract class method."""

    @staticmethod
    @abstractmethod
    def abstract_static_method():
        """Abstract static method."""

    @property  # type:ignore
    @abstractmethod
    def abstract_read_only_property(self):
        """Abstract read only property."""

    @property  # type:ignore
    @abstractmethod
    def abstract_read_write_property(self):
        """Abstract read write property."""

    @abstract_read_write_property.setter  # type:ignore
    @abstractmethod
    def abstract_read_write_property(self, val):
        pass
![mkapi](appendix.abc.AbstractMethodTypeExample|short)
abstract class
AbstractMethodTypeExample()

Abstract class.

Attributes
  • abstract_read_only_property Abstract read only property.
  • abstract_read_write_property Abstract read write property.
Methods
method
method()

Method.

classmethod
class_method()

Class method.

staticmethod
static_method()

Static method.

abstract method
abstract_method()

Abstract method.

abstract classmethod
abstract_class_method()

Abstract class method.

abstract staticmethod
abstract_static_method()

Abstract static method.