ninchat / python-slots

__init__ + decorator = __slots__

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Before:

class A:
    __slots__ = [
        'foo',
        'bar',
    ]

    def __init__(self):
        self.foo = 1
        self.bar = 2


class B(A):
    __slots__ = A.__slots__ + [
        'baz',
    ]

    def __init__(self):
        super().__init__()
        self.baz = 3

After:

import slot  # Alternatively: from slot import slots

class A:

      @slot.s
      def __init__(self):
          self.foo = 1
	  self.bar = 2


class B(A):

      @slot.s
      def __init__(self):
          super().__init__()
          self.baz = 3

Inspired by attrs.

About

__init__ + decorator = __slots__

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 100.0%