Skip to main content

@cls - Class Made Aware to Decorator

GitHub | CircleCI | Build Status | codecov

The purpose of this library is to provide possibility to create decorators, especially in super classes, with current class cls as argument. Everything are centered with our new cls module, keyword, magic, or what every you think it would be.

Get Start

A typical snippet looks like:

from functools import wraps
import cls


class Base(metaclass=cls.ClsMeta):
  @cls
  def decor(cls, decor_arg):
    def wrap(func):
      @wraps(func)
      def wrapper(self):
        # do something with `func`
        retval = func(self)
        # do something with `retval`
        return retval
      return wrapper
    return wrap

class Extended(Base):
  @cls.decor('some arg')
  def func(self):
    # do something
    pass

The magic is that you can use @cls.decor in Extended class, which is inheritance from Base. What is more, with in the decorator Base.decor, argument cls will be assigned with the correct current class. In this example, it would simply be a reference to Extended. This would be helpful if you want to make use of some class property here in the decorator.

Magic

Well, there is no magic. I created a delegator in class namespace to enable both class possible to use @cls. So, it is not the module cls as we imported on the top. I use this to make it more consistent looking, and fool some interpreters like pylint. No offense, just want to make them less noisy.

Limitations

Unfortunately, This work is based on customizing python class creation. I have to make use of __prepare__, which is introduced only to python 3. That means there is no known possible backward compatibility with python 2 now. The code is tested against python 3.5+.

Please let me know if you come up with an idea how to manipulate class creation in python 2.

There are a couple of issues, with which I am talking. Contributions are welcome.

Known issue

  • relying on length of arguments and callable() to support optional arguments in decorator
  • not compatible with @classmethod, or many other decorators
  • make pylint really noisy
  • no documents :see_no_evil:!

Metadata

Release files for acls 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for acls 1.0.0
File Size Uploaded Provenance Actions
acls-1.0.0.tar.gz 4.1 kB Without provenance Details for acls-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for acls 1.0.0
File Interpreter ABI Platform Actions
acls-1.0.0-py3-none-any.whl Python 3 none any Details for acls-1.0.0-py3-none-any.whl

Total release size: 9.6 kB

Release files / acls-1.0.0.tar.gz

Download URL acls-1.0.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
93cf0689e6ebaf33541d3442b1c3adb76cb7fd78c7aa8c0127027a347f7d2ea8
BLAKE2b-256 checksum
How to use checksums
1440a92eaeea775ab20deb139a565138470eec6f8b1b50acd678afe4ce3bd673
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / acls-1.0.0-py3-none-any.whl

Download URL acls-1.0.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0094a4752eab2366ab4f6b96177f33c1904fa6038fcf31de93c6f2f8a94e7eba
BLAKE2b-256 checksum
How to use checksums
66f8a5d2de58cc3296192eb7382ab64e2d156d3a03839913e57cf50dba8d13de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for acls 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page