Skip to content

Python decorators for classproperty and cached_classproperty

License

Notifications You must be signed in to change notification settings

hottwaj/classproperties

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

classproperties

Decorators for classproperty and cached_classproperty

Python 3 compatible only. No dependencies.

Installation

This package is not hosted on pypi but can be installed using pip using e.g.

pip install git+https://github.com/hottwaj/classproperties.git

Example usage

from classproperties import classproperty, cached_classproperty
class C(object):

    @classproperty
    def x(cls):
        return 1

assert C.x == 1
assert C().x == 1

class CCached(object):

    @cached_classproperty
    def x(cls):
        print('executed only once')
        return 1

assert CCached.x == 1
assert CCached().x == 1

Tests

See tests.py for example usage and expected behaviour

To run tests:

python tests.py

Credits

Credits to Denis Ryzhkov on Stackoverflow for the implementation of classproperty: https://stackoverflow.com/a/13624858/1280629

About

Python decorators for classproperty and cached_classproperty

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages