Skip to main content

fieldprop provides a decorator @field likes the @property. @field can be set getter, setter and deleter as well as @property. Moreover, you can add any handlers to @field.

Project description

fieldprop provides a decorator @field likes the @property. @field can be set getter, setter and deleter as well as @property. Moreover, you can add any handlers to @field. For example:

from fieldprop import field

class Foo(object):
    @field
    def foo(self):
        return self._foo

    @foo.setter
    def foo(self, v):
        self._foo = v

    @foo.deleter
    def foo(self):
        self._foo = None

    @foo.validator
    def foo(self):
        if self._foo is None:
            raise ValueError("'foo' must be set")

x = Foo()
x.foo = 123
print(x.foo) # 123
Foo.foo['validator'](x) # OK

del x.foo
Foo.foo['validator'](x) # NG

For more information, see example/*.py

LICENSE

This software is released under the MIT license, see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for fieldprop, version 2.1.0
Filename, size File type Python version Upload date Hashes
Filename, size fieldprop-2.1.0-py3-none-any.whl (5.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size fieldprop-2.1.0.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page