[Python-ideas] Adding an "export" decorator in (e.g.) functools
Berker Peksağ
berker.peksag at gmail.com
Fri May 9 09:06:47 CEST 2014
On Fri, May 9, 2014 at 8:38 AM, Bill Winslow <bunslow at gmail.com> wrote:
> Hey guys.
>
> This is simple pattern I've added to my own "myutils.py" file, which I think
> could see wide use if added to the standard library.
>
> Simply, it's the following function meant to be used primarily as a
> decorator.
>
> def export(func):
> global __all__
> if callable(func) and hasattr(func, '__name__'):
> try:
> __all__.append(func.__name__)
> except NameError:
> __all__ = [func.__name__]
> return func
Here's a simpler implementation:
http://hg.python.org/release/file/b270b4d5cf2c/3.4/dryparse/dryparse.py#l57
--Berker
More information about the Python-ideas
mailing list