Catalog PyPI
Back to packageRELEASE DETAILS

1.0.2

PyPI

acls

`@cls` - Class Made Aware to Decorator

Published29 Jun 2019
Direct dependencies0
Transitive dependenciesNot calculated

README

Version 1.0.2 documentation

@cls - Class Made Aware to Decorator

PyPI - License PyPI PyPI - Status PyPI - Python Version

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.

Getting Started

Installation

Install by pip from PyPI:

pip install acls

Example

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:!

License

MIT License, Copyright (c) 2019 guoquan

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

1 collected
acls-1.0.2.tar.gz

sdist · 4.17 KB · Python source

Source file

Repository

ACCESSIBLE
guoquan/acls

Shared repository data · GitHub

License detected in repository
MIT
License branch / ref
master
Last push
25 Aug 2022
Archived
No
Contributor identities
— · partial collection

Public sponsor counts have not been collected. These signals belong to the repository owner.

Downloads & popularity

0count
Gauge · observed snapshots21 Oct 2026
10.50
2026-10-21: 0 · observed 2026-10-21T18:41:25.6753687Z
21 Oct21 Oct

github · 1 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-2102026-10-21T18:41:25.6753687Z

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:17 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:c5dc20b72d2f0a275b664fa4444d948e32b89ab3ed7c3b1938dd4faa9cc703be

Other collected versions

View all collected versions →